Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
7b11e73b
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7b11e73b
编写于
4月 04, 2019
作者:
Q
Qiyang Min
提交者:
GitHub
4月 04, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16660 from velconia/imperative_dqn
Imperative test layers without parameters
上级
0d6581c5
7c4b9b57
变更
3
展开全部
显示空白变更内容
内联
并排
Showing
3 changed file
with
801 addition
and
782 deletion
+801
-782
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+5
-5
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+39
-1
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+757
-776
未找到文件。
python/paddle/fluid/dygraph/nn.py
浏览文件 @
7b11e73b
...
@@ -48,7 +48,7 @@ class Conv2D(layers.Layer):
...
@@ -48,7 +48,7 @@ class Conv2D(layers.Layer):
bias_attr
=
None
,
bias_attr
=
None
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
):
dtype
=
core
.
VarDesc
.
VarType
.
FP32
):
assert
param_attr
is
not
False
,
"param_attr should not be False here."
assert
param_attr
is
not
False
,
"param_attr should not be False here."
super
(
Conv2D
,
self
).
__init__
(
name_scope
)
super
(
Conv2D
,
self
).
__init__
(
name_scope
,
dtype
)
self
.
_groups
=
groups
self
.
_groups
=
groups
self
.
_stride
=
utils
.
convert_to_list
(
stride
,
2
,
'stride'
)
self
.
_stride
=
utils
.
convert_to_list
(
stride
,
2
,
'stride'
)
self
.
_padding
=
utils
.
convert_to_list
(
padding
,
2
,
'padding'
)
self
.
_padding
=
utils
.
convert_to_list
(
padding
,
2
,
'padding'
)
...
@@ -503,7 +503,7 @@ class FC(layers.Layer):
...
@@ -503,7 +503,7 @@ class FC(layers.Layer):
num_flatten_dims
=
1
,
num_flatten_dims
=
1
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
,
act
=
None
):
act
=
None
):
super
(
FC
,
self
).
__init__
(
name_scope
)
super
(
FC
,
self
).
__init__
(
name_scope
,
dtype
)
self
.
_size
=
size
self
.
_size
=
size
self
.
_num_flatten_dims
=
num_flatten_dims
self
.
_num_flatten_dims
=
num_flatten_dims
...
@@ -608,7 +608,7 @@ class BatchNorm(layers.Layer):
...
@@ -608,7 +608,7 @@ class BatchNorm(layers.Layer):
do_model_average_for_mean_and_var
=
False
,
do_model_average_for_mean_and_var
=
False
,
fuse_with_relu
=
False
,
fuse_with_relu
=
False
,
use_global_stats
=
False
):
use_global_stats
=
False
):
super
(
BatchNorm
,
self
).
__init__
(
name_scope
)
super
(
BatchNorm
,
self
).
__init__
(
name_scope
,
dtype
)
self
.
_param_attr
=
param_attr
self
.
_param_attr
=
param_attr
self
.
_param_attr
=
bias_attr
self
.
_param_attr
=
bias_attr
self
.
_act
=
act
self
.
_act
=
act
...
@@ -760,7 +760,7 @@ class Embedding(layers.Layer):
...
@@ -760,7 +760,7 @@ class Embedding(layers.Layer):
param_attr
=
None
,
param_attr
=
None
,
dtype
=
'float32'
):
dtype
=
'float32'
):
super
(
Embedding
,
self
).
__init__
(
name_scope
)
super
(
Embedding
,
self
).
__init__
(
name_scope
,
dtype
)
self
.
_size
=
size
self
.
_size
=
size
self
.
_is_sparse
=
is_sparse
self
.
_is_sparse
=
is_sparse
self
.
_is_distributed
=
is_distributed
self
.
_is_distributed
=
is_distributed
...
@@ -1008,7 +1008,7 @@ class GRUUnit(layers.Layer):
...
@@ -1008,7 +1008,7 @@ class GRUUnit(layers.Layer):
gate_activation
=
'sigmoid'
,
gate_activation
=
'sigmoid'
,
origin_mode
=
False
,
origin_mode
=
False
,
dtype
=
'float32'
):
dtype
=
'float32'
):
super
(
GRUUnit
,
self
).
__init__
(
name_scope
)
super
(
GRUUnit
,
self
).
__init__
(
name_scope
,
dtype
)
activation_dict
=
dict
(
activation_dict
=
dict
(
identity
=
0
,
identity
=
0
,
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
7b11e73b
...
@@ -481,6 +481,8 @@ def dynamic_lstm(input,
...
@@ -481,6 +481,8 @@ def dynamic_lstm(input,
forward, _ = fluid.layers.dynamic_lstm(
forward, _ = fluid.layers.dynamic_lstm(
input=forward_proj, size=hidden_dim * 4, use_peepholes=False)
input=forward_proj, size=hidden_dim * 4, use_peepholes=False)
"""
"""
assert
_in_dygraph_mode
(
)
is
not
True
,
"please use lstm instead of dynamic_lstm in dygraph mode!"
assert
bias_attr
is
not
False
,
"bias_attr should not be False in dynamic_lstmp."
assert
bias_attr
is
not
False
,
"bias_attr should not be False in dynamic_lstmp."
helper
=
LayerHelper
(
'lstm'
,
**
locals
())
helper
=
LayerHelper
(
'lstm'
,
**
locals
())
size
=
size
//
4
size
=
size
//
4
...
@@ -865,6 +867,9 @@ def dynamic_lstmp(input,
...
@@ -865,6 +867,9 @@ def dynamic_lstmp(input,
proj_activation="tanh")
proj_activation="tanh")
"""
"""
assert
_in_dygraph_mode
(
)
is
not
True
,
"please use lstm instead of dynamic_lstmp in dygraph mode!"
assert
bias_attr
is
not
False
,
"bias_attr should not be False in dynamic_lstmp."
assert
bias_attr
is
not
False
,
"bias_attr should not be False in dynamic_lstmp."
helper
=
LayerHelper
(
'lstmp'
,
**
locals
())
helper
=
LayerHelper
(
'lstmp'
,
**
locals
())
size
=
size
//
4
size
=
size
//
4
...
@@ -1036,6 +1041,9 @@ def dynamic_gru(input,
...
@@ -1036,6 +1041,9 @@ def dynamic_gru(input,
hidden = fluid.layers.dynamic_gru(input=x, size=hidden_dim)
hidden = fluid.layers.dynamic_gru(input=x, size=hidden_dim)
"""
"""
assert
_in_dygraph_mode
(
)
is
not
True
,
"please use gru instead of dynamic_gru in dygraph mode!"
helper
=
LayerHelper
(
'gru'
,
**
locals
())
helper
=
LayerHelper
(
'gru'
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
...
@@ -1752,6 +1760,8 @@ def sequence_conv(input,
...
@@ -1752,6 +1760,8 @@ def sequence_conv(input,
Variable: output of sequence_conv
Variable: output of sequence_conv
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_conv'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_conv'
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
filter_shape
=
[
filter_size
*
input
.
shape
[
1
],
num_filters
]
filter_shape
=
[
filter_size
*
input
.
shape
[
1
],
num_filters
]
...
@@ -1811,6 +1821,8 @@ def sequence_softmax(input, use_cudnn=False, name=None):
...
@@ -1811,6 +1821,8 @@ def sequence_softmax(input, use_cudnn=False, name=None):
dtype='float32', lod_level=1)
dtype='float32', lod_level=1)
x_sequence_softmax = fluid.layers.sequence_softmax(input=x)
x_sequence_softmax = fluid.layers.sequence_softmax(input=x)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_softmax'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_softmax'
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
softmax_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
softmax_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -2303,6 +2315,8 @@ def sequence_pool(input, pool_type, is_test=False):
...
@@ -2303,6 +2315,8 @@ def sequence_pool(input, pool_type, is_test=False):
last_x = fluid.layers.sequence_pool(input=x, pool_type='last')
last_x = fluid.layers.sequence_pool(input=x, pool_type='last')
first_x = fluid.layers.sequence_pool(input=x, pool_type='first')
first_x = fluid.layers.sequence_pool(input=x, pool_type='first')
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_pool'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_pool'
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
pool_out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -2342,6 +2356,8 @@ def sequence_concat(input, name=None):
...
@@ -2342,6 +2356,8 @@ def sequence_concat(input, name=None):
out = fluid.layers.sequence_concat(input=[seq1, seq2, seq3])
out = fluid.layers.sequence_concat(input=[seq1, seq2, seq3])
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_concat'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_concat'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
helper
.
input_dtype
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
helper
.
input_dtype
())
helper
.
append_op
(
helper
.
append_op
(
...
@@ -2469,6 +2485,8 @@ def sequence_slice(input, offset, length, name=None):
...
@@ -2469,6 +2485,8 @@ def sequence_slice(input, offset, length, name=None):
subseqs = fluid.layers.sequence_slice(input=seqs, offset=offset,
subseqs = fluid.layers.sequence_slice(input=seqs, offset=offset,
length=length)
length=length)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
"sequence_slice"
,
**
locals
())
helper
=
LayerHelper
(
"sequence_slice"
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -3928,6 +3946,8 @@ def sequence_expand(x, y, ref_level=-1, name=None):
...
@@ -3928,6 +3946,8 @@ def sequence_expand(x, y, ref_level=-1, name=None):
dtype='float32', lod_level=1)
dtype='float32', lod_level=1)
out = layers.sequence_expand(x=x, y=y, ref_level=0)
out = layers.sequence_expand(x=x, y=y, ref_level=0)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_expand'
,
input
=
x
,
**
locals
())
helper
=
LayerHelper
(
'sequence_expand'
,
input
=
x
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
tmp
=
helper
.
create_variable_for_type_inference
(
dtype
)
tmp
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -3994,6 +4014,8 @@ def sequence_expand_as(x, y, name=None):
...
@@ -3994,6 +4014,8 @@ def sequence_expand_as(x, y, name=None):
dtype='float32', lod_level=1)
dtype='float32', lod_level=1)
out = layers.sequence_expand_as(x=x, y=y)
out = layers.sequence_expand_as(x=x, y=y)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_expand_as'
,
input
=
x
,
**
locals
())
helper
=
LayerHelper
(
'sequence_expand_as'
,
input
=
x
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
tmp
=
helper
.
create_variable_for_type_inference
(
dtype
)
tmp
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -4040,6 +4062,8 @@ def sequence_pad(x, pad_value, maxlen=None, name=None):
...
@@ -4040,6 +4062,8 @@ def sequence_pad(x, pad_value, maxlen=None, name=None):
out = fluid.layers.sequence_pad(x=x, pad_value=pad_value)
out = fluid.layers.sequence_pad(x=x, pad_value=pad_value)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_pad'
,
input
=
x
,
**
locals
())
helper
=
LayerHelper
(
'sequence_pad'
,
input
=
x
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -4106,6 +4130,8 @@ def sequence_unpad(x, length, name=None):
...
@@ -4106,6 +4130,8 @@ def sequence_unpad(x, length, name=None):
out = fluid.layers.sequence_unpad(x=x, length=len)
out = fluid.layers.sequence_unpad(x=x, length=len)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_unpad'
,
input
=
x
,
**
locals
())
helper
=
LayerHelper
(
'sequence_unpad'
,
input
=
x
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -5279,6 +5305,8 @@ def sequence_reshape(input, new_dim):
...
@@ -5279,6 +5305,8 @@ def sequence_reshape(input, new_dim):
x = fluid.layers.data(shape=[5, 20], dtype='float32', lod_level=1)
x = fluid.layers.data(shape=[5, 20], dtype='float32', lod_level=1)
x_reshaped = fluid.layers.sequence_reshape(input=x, new_dim=10)
x_reshaped = fluid.layers.sequence_reshape(input=x, new_dim=10)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_reshape'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_reshape'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
helper
.
input_dtype
())
out
=
helper
.
create_variable_for_type_inference
(
helper
.
input_dtype
())
helper
.
append_op
(
helper
.
append_op
(
...
@@ -5813,6 +5841,8 @@ def im2sequence(input,
...
@@ -5813,6 +5841,8 @@ def im2sequence(input,
input=layer, stride=[1, 1], filter_size=[2, 2])
input=layer, stride=[1, 1], filter_size=[2, 2])
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
if
isinstance
(
filter_size
,
int
):
if
isinstance
(
filter_size
,
int
):
filter_size
=
[
filter_size
,
filter_size
]
filter_size
=
[
filter_size
,
filter_size
]
...
@@ -6229,7 +6259,7 @@ def smooth_l1(x, y, inside_weight=None, outside_weight=None, sigma=None):
...
@@ -6229,7 +6259,7 @@ def smooth_l1(x, y, inside_weight=None, outside_weight=None, sigma=None):
},
},
outputs
=
{
'Diff'
:
diff
,
outputs
=
{
'Diff'
:
diff
,
'Out'
:
loss
},
'Out'
:
loss
},
attrs
=
{
'sigma'
:
sigma
})
attrs
=
{
'sigma'
:
sigma
if
sigma
is
not
None
else
1.0
})
return
loss
return
loss
...
@@ -7590,6 +7620,8 @@ def sequence_scatter(input, index, updates, name=None):
...
@@ -7590,6 +7620,8 @@ def sequence_scatter(input, index, updates, name=None):
output = fluid.layers.sequence_scatter(input, index, updates)
output = fluid.layers.sequence_scatter(input, index, updates)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_scatter'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_scatter'
,
**
locals
())
dtype
=
helper
.
input_dtype
()
dtype
=
helper
.
input_dtype
()
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
...
@@ -8678,6 +8710,8 @@ def sequence_enumerate(input, win_size, pad_value=0, name=None):
...
@@ -8678,6 +8710,8 @@ def sequence_enumerate(input, win_size, pad_value=0, name=None):
x = fluid.layers.data(shape[30, 1], dtype='int32', lod_level=1)
x = fluid.layers.data(shape[30, 1], dtype='int32', lod_level=1)
out = fluid.layers.sequence_enumerate(input=x, win_size=3, pad_value=0)
out = fluid.layers.sequence_enumerate(input=x, win_size=3, pad_value=0)
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_enumerate'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_enumerate'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
out
=
helper
.
create_variable_for_type_inference
(
helper
.
input_dtype
(),
stop_gradient
=
True
)
helper
.
input_dtype
(),
stop_gradient
=
True
)
...
@@ -8717,6 +8751,8 @@ def sequence_mask(x, maxlen=None, dtype='int64', name=None):
...
@@ -8717,6 +8751,8 @@ def sequence_mask(x, maxlen=None, dtype='int64', name=None):
Variable: The output sequence mask.
Variable: The output sequence mask.
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
'sequence_mask'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_mask'
,
**
locals
())
if
name
is
None
:
if
name
is
None
:
...
@@ -9767,6 +9803,8 @@ def sequence_reverse(x, name=None):
...
@@ -9767,6 +9803,8 @@ def sequence_reverse(x, name=None):
Returns:
Returns:
out(${y_type}): ${y_comment}
out(${y_type}): ${y_comment}
"""
"""
assert
not
_in_dygraph_mode
(),
(
"sequence layer is not supported in dygraph mode yet."
)
helper
=
LayerHelper
(
"sequence_reverse"
,
**
locals
())
helper
=
LayerHelper
(
"sequence_reverse"
,
**
locals
())
if
name
is
None
:
if
name
is
None
:
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
x
.
dtype
)
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
7b11e73b
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录