Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
d4d5052f
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4d5052f
编写于
3月 29, 2019
作者:
L
lujun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix merge for move dir, fix utest error, test=develop
上级
32146857
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
21 deletion
+19
-21
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+15
-12
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+4
-9
未找到文件。
python/paddle/fluid/dygraph/nn.py
浏览文件 @
d4d5052f
...
...
@@ -19,7 +19,7 @@ from six.moves import reduce
from
..
import
core
from
..layers
import
utils
from
.
import
layers
from
..framework
import
Variable
from
..framework
import
Variable
,
_in_dygraph_mode
from
..param_attr
import
ParamAttr
from
..initializer
import
Normal
,
Constant
,
NumpyArrayInitializer
import
numpy
as
np
...
...
@@ -1560,6 +1560,8 @@ class SequenceConv(layers.Layer):
bias_attr
=
None
,
param_attr
=
None
,
act
=
None
):
assert
not
_in_dygraph_mode
(),
\
"SequenceConv is not supported by dynamic graph mode yet!"
super
(
SequenceConv
,
self
).
__init__
(
name_scope
)
self
.
_num_filters
=
num_filters
self
.
_filter_size
=
filter_size
...
...
@@ -1569,12 +1571,10 @@ class SequenceConv(layers.Layer):
self
.
_param_attr
=
param_attr
def
_build_once
(
self
,
input
):
self
.
_dtype
=
self
.
_helper
.
input_dtype
(
input
)
print
(
self
.
_filter_size
)
filter_shape
=
[
self
.
_filter_size
*
input
.
shape
[
1
],
self
.
_num_filters
]
self
.
_filter_param
=
self
.
create_parameter
(
attr
=
self
.
param_attr
,
shape
=
filter_shape
,
dtype
=
self
.
_dtype
)
attr
=
self
.
_
param_attr
,
shape
=
filter_shape
,
dtype
=
self
.
_dtype
)
def
forward
(
self
,
input
):
pre_bias
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
...
...
@@ -1600,23 +1600,28 @@ class RowConv(layers.Layer):
future_context_size
,
param_attr
=
None
,
act
=
None
):
assert
not
_in_dygraph_mode
(),
\
"RowConv is not supported by dynamic graph mode yet!"
super
(
RowConv
,
self
).
__init__
(
name_scope
)
self
.
_act
=
act
self
.
_param_attr
=
param_attr
self
.
_future_context_size
=
future_context_size
def
_buil
s
_once
(
self
,
input
):
def
_buil
d
_once
(
self
,
input
):
self
.
_dtype
=
self
.
_helper
.
input_dtype
(
input
)
filter_shape
=
[
self
.
_future_context_size
+
1
,
input
.
shape
[
1
]]
self
.
_f
=
self
.
create_parameter
(
attr
=
self
.
_param_attr
,
shape
=
filter_shape
,
dtype
=
self
.
_dtype
)
self
.
_filter_param
=
self
.
create_parameter
(
attr
=
self
.
_param_attr
,
shape
=
filter_shape
,
dtype
=
self
.
_dtype
,
is_bias
=
False
)
def
forward
(
self
,
input
):
out
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
self
.
_helper
.
append_op
(
type
=
'row_conv'
,
inputs
=
{
'X'
:
[
input
],
'Filter'
:
[
self
.
_f
]},
'Filter'
:
[
self
.
_f
ilter_param
]},
outputs
=
{
'Out'
:
[
out
]})
return
self
.
_helper
.
append_activation
(
out
,
act
=
self
.
_act
)
...
...
@@ -1665,7 +1670,7 @@ class GroupNorm(layers.Layer):
if
data_layout
!=
'NCHW'
:
raise
ValueError
(
"unsupported data layout:"
+
data_layout
)
def
_buil
s
_once
(
self
,
input
):
def
_buil
d
_once
(
self
,
input
):
self
.
_dtype
=
self
.
_helper
.
input_dtype
(
input
)
param_shape
=
[
input
.
shape
[
1
]]
if
self
.
_bias_attr
:
...
...
@@ -1690,10 +1695,8 @@ class GroupNorm(layers.Layer):
inputs
[
'Scale'
]
=
self
.
_scale
# create output
mean_out
=
self
.
_helper
.
create_variable
(
mean_out
=
self
.
_helper
.
create_variable
_for_type_inference
(
dtype
=
self
.
_dtype
,
stop_gradient
=
True
)
self
.
create_variable
(
name
=
"mean_out"
,
persistable
=
True
,
type
=
self
.
_dtype
)
variance_out
=
self
.
_helper
.
create_variable_for_type_inference
(
dtype
=
self
.
_dtype
,
stop_gradient
=
True
)
group_norm_out
=
self
.
_helper
.
create_variable_for_type_inference
(
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
d4d5052f
...
...
@@ -626,18 +626,13 @@ class TestLayer(LayerTest):
static_ret2
=
self
.
get_static_graph_result
(
feed
=
{
'X'
:
fluid
.
create_lod_tensor
(
data
=
input
,
recursive_seq_lens
=
[[
1
,
1
,
1
]],
place
=
place
,
with_lod
=
True
)
data
=
input
,
recursive_seq_lens
=
[[
1
,
1
,
1
]],
place
=
place
)
},
fetch_list
=
[
ret
])[
0
]
fetch_list
=
[
ret
],
with_lod
=
True
)[
0
]
with
self
.
dynamic_graph
():
rowConv
=
nn
.
RowConv
(
'RowConv'
,
future_context_size
=
2
)
dy_ret
=
rowConv
(
base
.
to_variable
(
input
))
# TODO: dygraph can't support LODTensor
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
dy_ret
.
_numpy
()))
self
.
assertTrue
(
np
.
allclose
(
static_ret
,
static_ret2
))
def
test_group_norm
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录