Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
fff67a94
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fff67a94
编写于
1月 28, 2019
作者:
J
JiabinYang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test=develop, use parameters() to get parameters
上级
2e309b11
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
6 deletion
+22
-6
python/paddle/fluid/imperative/nn.py
python/paddle/fluid/imperative/nn.py
+3
-0
python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py
...n/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py
+19
-6
未找到文件。
python/paddle/fluid/imperative/nn.py
浏览文件 @
fff67a94
...
@@ -483,6 +483,9 @@ class Embedding(layers.Layer):
...
@@ -483,6 +483,9 @@ class Embedding(layers.Layer):
dtype
=
self
.
_dtype
,
dtype
=
self
.
_dtype
,
is_bias
=
False
)
is_bias
=
False
)
def
parameters
(
self
):
return
[
self
.
_w
]
def
forward
(
self
,
input
):
def
forward
(
self
,
input
):
out
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
out
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
self
.
_helper
.
append_op
(
self
.
_helper
.
append_op
(
...
...
python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py
浏览文件 @
fff67a94
...
@@ -75,6 +75,16 @@ class SimpleLSTMRNN(fluid.imperative.Layer):
...
@@ -75,6 +75,16 @@ class SimpleLSTMRNN(fluid.imperative.Layer):
self
.
hidden_array
.
append
(
pre_hidden
)
self
.
hidden_array
.
append
(
pre_hidden
)
self
.
cell_array
.
append
(
pre_cell
)
self
.
cell_array
.
append
(
pre_cell
)
def
parameters
(
self
):
parameters
=
list
()
for
param
in
self
.
weight_1_arr
:
parameters
.
append
(
param
)
for
param
in
self
.
weight_2_arr
:
parameters
.
append
(
param
)
for
bias
in
self
.
bias_arr
:
parameters
.
append
(
bias
)
return
parameters
def
forward
(
self
,
input_embedding
,
init_hidden
=
None
,
init_cell
=
None
):
def
forward
(
self
,
input_embedding
,
init_hidden
=
None
,
init_cell
=
None
):
res
=
[]
res
=
[]
for
index
in
range
(
self
.
_num_steps
):
for
index
in
range
(
self
.
_num_steps
):
...
@@ -167,6 +177,12 @@ class PtbModel(fluid.imperative.Layer):
...
@@ -167,6 +177,12 @@ class PtbModel(fluid.imperative.Layer):
def
_build_once
(
self
,
input
,
label
,
init_hidden
,
init_cell
):
def
_build_once
(
self
,
input
,
label
,
init_hidden
,
init_cell
):
pass
pass
def
parameters
(
self
):
parameters
=
self
.
simple_lstm_rnn
.
parameters
()
+
[
self
.
softmax_weight
,
self
.
softmax_bias
]
+
self
.
embedding
.
parameters
()
return
parameters
def
forward
(
self
,
input
,
label
,
init_hidden
,
init_cell
):
def
forward
(
self
,
input
,
label
,
init_hidden
,
init_cell
):
init_h
=
fluid
.
layers
.
reshape
(
init_h
=
fluid
.
layers
.
reshape
(
...
@@ -246,13 +262,11 @@ class TestImperativePtbRnn(unittest.TestCase):
...
@@ -246,13 +262,11 @@ class TestImperativePtbRnn(unittest.TestCase):
dy_loss
,
last_hidden
,
last_cell
=
ptb_model
(
x
,
y
,
init_hidden
,
dy_loss
,
last_hidden
,
last_cell
=
ptb_model
(
x
,
y
,
init_hidden
,
init_cell
)
init_cell
)
if
i
==
0
:
if
i
==
0
:
for
param
in
fluid
.
default_main_program
().
global_block
(
for
param
in
ptb_model
.
parameters
():
).
all_parameters
():
dy_param_init
[
param
.
name
]
=
param
.
_numpy
()
dy_param_init
[
param
.
name
]
=
param
.
_numpy
()
dy_loss
.
_backward
()
dy_loss
.
_backward
()
sgd
.
minimize
(
dy_loss
)
sgd
.
minimize
(
dy_loss
)
for
param
in
fluid
.
default_main_program
().
global_block
(
for
param
in
ptb_model
.
parameters
():
).
all_parameters
():
dy_param_updated
[
param
.
name
]
=
param
.
_numpy
()
dy_param_updated
[
param
.
name
]
=
param
.
_numpy
()
# print("dy_loss is {}".format(dy_loss._numpy()))
# print("dy_loss is {}".format(dy_loss._numpy()))
# print("last_hidden is {}".format(last_hidden._numpy()))
# print("last_hidden is {}".format(last_hidden._numpy()))
...
@@ -284,8 +298,7 @@ class TestImperativePtbRnn(unittest.TestCase):
...
@@ -284,8 +298,7 @@ class TestImperativePtbRnn(unittest.TestCase):
static_param_updated
=
dict
()
static_param_updated
=
dict
()
static_param_init
=
dict
()
static_param_init
=
dict
()
static_param_name_list
=
list
()
static_param_name_list
=
list
()
for
param
in
fluid
.
default_startup_program
().
global_block
(
for
param
in
ptb_model
.
parameters
():
).
all_parameters
():
static_param_name_list
.
append
(
param
.
name
)
static_param_name_list
.
append
(
param
.
name
)
out
=
exe
.
run
(
framework
.
default_startup_program
(),
out
=
exe
.
run
(
framework
.
default_startup_program
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录