Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2e3f2af7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2e3f2af7
编写于
8月 28, 2017
作者:
C
Cao Ying
提交者:
GitHub
8月 28, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3701 from lcy-seso/save_parameter_name_in_ordereddict
save parameters into OrderedDict and refine the comments.
上级
14065ef9
f0b25c4c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
25 addition
and
5 deletion
+25
-5
python/paddle/v2/parameters.py
python/paddle/v2/parameters.py
+25
-5
未找到文件。
python/paddle/v2/parameters.py
浏览文件 @
2e3f2af7
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
import
numpy
as
np
import
numpy
as
np
from
paddle.proto.ParameterConfig_pb2
import
ParameterConfig
from
paddle.proto.ParameterConfig_pb2
import
ParameterConfig
from
collections
import
OrderedDict
import
paddle.trainer.config_parser
as
cp
import
paddle.trainer.config_parser
as
cp
import
struct
import
struct
import
tarfile
import
tarfile
...
@@ -42,9 +43,25 @@ def create(layers):
...
@@ -42,9 +43,25 @@ def create(layers):
class
Parameters
(
object
):
class
Parameters
(
object
):
"""
"""
Parameters is a dictionary contains Paddle's parameter. The key of
`Parameters` manages all the learnable parameters in a neural network.
Parameters is the name of parameter. The value of Parameters is a plain
It stores parameters' information in an OrderedDict. The key is
:code:`numpy.ndarry` .
the name of a parameter, and value is a parameter's configuration(in
protobuf format), such as initialization mean and std, its size, whether it
is a static parameter, and so on.
:param __param_conf__: store the configurations of learnable parameters in
the network in an OrderedDict. Parameter is added one by one into the
dict by following their created order in the network: parameters of
the previous layers in a network are careted first. You can visit the
parameters from bottom to top by iterating over this dict.
:type __param_conf__: OrderedDict
:param __gradient_machines__: all of the parameters in a neural network are
appended to a PaddlePaddle gradient machine, which is used internally to
copy parameter values between C++ and Python end.
:type __gradient_machines__: list
:param __tmp_params__: a dict to store dummy parameters if no
__gradient_machines__ is appended to `Parameters`.
:type __tmp_params__: dict
Basically usage is
Basically usage is
...
@@ -62,7 +79,7 @@ class Parameters(object):
...
@@ -62,7 +79,7 @@ class Parameters(object):
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
__param_conf__
=
d
ict
()
self
.
__param_conf__
=
OrderedD
ict
()
self
.
__gradient_machines__
=
[]
self
.
__gradient_machines__
=
[]
self
.
__tmp_params__
=
dict
()
self
.
__tmp_params__
=
dict
()
...
@@ -231,6 +248,9 @@ class Parameters(object):
...
@@ -231,6 +248,9 @@ class Parameters(object):
:rtype: np.ndarray
:rtype: np.ndarray
"""
"""
import
py_paddle.swig_paddle
as
api
import
py_paddle.swig_paddle
as
api
if
self
.
__param_conf__
[
key
].
is_static
:
return
np
.
zeros
(
self
.
__param_conf__
[
key
].
size
,
dtype
=
np
.
float32
)
return
self
.
__getter_inner
(
key
,
api
.
PARAMETER_GRADIENT
)
return
self
.
__getter_inner
(
key
,
api
.
PARAMETER_GRADIENT
)
def
set
(
self
,
parameter_name
,
value
):
def
set
(
self
,
parameter_name
,
value
):
...
@@ -250,7 +270,7 @@ class Parameters(object):
...
@@ -250,7 +270,7 @@ class Parameters(object):
append gradient machine to parameters. This method is used internally in
append gradient machine to parameters. This method is used internally in
Trainer.train.
Trainer.train.
:param gradient_machine: Paddle C++ GradientMachine object.
:param gradient_machine: Paddle
Paddle
C++ GradientMachine object.
:type gradient_machine: api.GradientMachine
:type gradient_machine: api.GradientMachine
:return:
:return:
"""
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录