Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
88d87a5f
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
提交
88d87a5f
编写于
1月 17, 2020
作者:
S
songyouwei
提交者:
hong
1月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cherry-pick #22333 (#22345)
test=release/1.7, test=develop
上级
c180ee8a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
0 deletion
+10
-0
python/paddle/fluid/dygraph/layers.py
python/paddle/fluid/dygraph/layers.py
+8
-0
python/paddle/fluid/tests/unittests/test_imperative_basic.py
python/paddle/fluid/tests/unittests/test_imperative_basic.py
+2
-0
未找到文件。
python/paddle/fluid/dygraph/layers.py
浏览文件 @
88d87a5f
...
@@ -369,6 +369,11 @@ class Layer(core.Layer):
...
@@ -369,6 +369,11 @@ class Layer(core.Layer):
return
object
.
__getattribute__
(
self
,
name
)
return
object
.
__getattribute__
(
self
,
name
)
def
__setattr__
(
self
,
name
,
value
):
def
__setattr__
(
self
,
name
,
value
):
def
_remove_if_exist
(
*
dicts
):
for
d
in
dicts
:
if
name
in
d
:
del
d
[
name
]
if
isinstance
(
getattr
(
type
(
self
),
name
,
None
),
property
):
if
isinstance
(
getattr
(
type
(
self
),
name
,
None
),
property
):
object
.
__setattr__
(
self
,
name
,
value
)
object
.
__setattr__
(
self
,
name
,
value
)
if
isinstance
(
value
,
framework
.
Parameter
):
if
isinstance
(
value
,
framework
.
Parameter
):
...
@@ -382,12 +387,15 @@ class Layer(core.Layer):
...
@@ -382,12 +387,15 @@ class Layer(core.Layer):
value
.
set_value
(
self
.
_loaddict_holder
[
value
.
name
])
value
.
set_value
(
self
.
_loaddict_holder
[
value
.
name
])
_remove_if_exist
(
self
.
__dict__
,
self
.
_sub_layers
)
params
[
name
]
=
value
params
[
name
]
=
value
elif
isinstance
(
value
,
core
.
Layer
):
elif
isinstance
(
value
,
core
.
Layer
):
layers
=
self
.
__dict__
.
get
(
'_sub_layers'
,
None
)
layers
=
self
.
__dict__
.
get
(
'_sub_layers'
,
None
)
if
layers
is
None
:
if
layers
is
None
:
raise
ValueError
(
raise
ValueError
(
"super(YourLayer, self).__init__() should be called first"
)
"super(YourLayer, self).__init__() should be called first"
)
_remove_if_exist
(
self
.
__dict__
,
self
.
_parameters
)
layers
[
name
]
=
value
layers
[
name
]
=
value
else
:
else
:
object
.
__setattr__
(
self
,
name
,
value
)
object
.
__setattr__
(
self
,
name
,
value
)
...
...
python/paddle/fluid/tests/unittests/test_imperative_basic.py
浏览文件 @
88d87a5f
...
@@ -37,6 +37,7 @@ class MyLayer(fluid.Layer):
...
@@ -37,6 +37,7 @@ class MyLayer(fluid.Layer):
class
MLP
(
fluid
.
Layer
):
class
MLP
(
fluid
.
Layer
):
def
__init__
(
self
,
input_size
):
def
__init__
(
self
,
input_size
):
super
(
MLP
,
self
).
__init__
()
super
(
MLP
,
self
).
__init__
()
self
.
_linear1
=
None
self
.
_linear1
=
Linear
(
self
.
_linear1
=
Linear
(
input_size
,
input_size
,
3
,
3
,
...
@@ -71,6 +72,7 @@ class SimpleRNNCell(fluid.Layer):
...
@@ -71,6 +72,7 @@ class SimpleRNNCell(fluid.Layer):
i2h_param_shape
=
[
self
.
step_input_size
,
self
.
hidden_size
]
i2h_param_shape
=
[
self
.
step_input_size
,
self
.
hidden_size
]
h2h_param_shape
=
[
self
.
hidden_size
,
self
.
hidden_size
]
h2h_param_shape
=
[
self
.
hidden_size
,
self
.
hidden_size
]
h2o_param_shape
=
[
self
.
output_size
,
self
.
hidden_size
]
h2o_param_shape
=
[
self
.
output_size
,
self
.
hidden_size
]
self
.
_i2h_w
=
None
self
.
_i2h_w
=
self
.
create_parameter
(
self
.
_i2h_w
=
self
.
create_parameter
(
attr
=
self
.
param_attr
,
attr
=
self
.
param_attr
,
shape
=
i2h_param_shape
,
shape
=
i2h_param_shape
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录