Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0c8f69c3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
0c8f69c3
编写于
7月 12, 2018
作者:
Y
yuyang18
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Hide more APIs
上级
6eba4b32
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
20 deletion
+20
-20
python/paddle/fluid/layer_helper.py
python/paddle/fluid/layer_helper.py
+11
-11
python/paddle/fluid/param_attr.py
python/paddle/fluid/param_attr.py
+9
-9
未找到文件。
python/paddle/fluid/layer_helper.py
浏览文件 @
0c8f69c3
...
...
@@ -68,11 +68,11 @@ class LayerHelper(object):
@
property
def
param_attr
(
self
):
return
ParamAttr
.
to_attr
(
self
.
kwargs
.
get
(
'param_attr'
,
None
))
return
ParamAttr
.
_
to_attr
(
self
.
kwargs
.
get
(
'param_attr'
,
None
))
@
property
def
bias_attr
(
self
):
return
ParamAttr
.
to_attr
(
self
.
kwargs
.
get
(
'bias_attr'
,
None
))
return
ParamAttr
.
_
to_attr
(
self
.
kwargs
.
get
(
'bias_attr'
,
None
))
def
multiple_param_attr
(
self
,
length
):
param_attr
=
self
.
param_attr
...
...
@@ -262,11 +262,11 @@ class LayerHelper(object):
g_param
=
self
.
startup_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
g_param_shape
,
**
g_param_attr
.
to_kwargs
(
with_initializer
=
False
))
**
g_param_attr
.
_
to_kwargs
(
with_initializer
=
False
))
v_param
=
self
.
startup_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
v_param_shape
,
**
v_param_attr
.
to_kwargs
(
with_initializer
=
True
))
**
v_param_attr
.
_
to_kwargs
(
with_initializer
=
True
))
__norm_except_dim
(
x
=
v_param
,
out
=
g_param
,
...
...
@@ -275,9 +275,9 @@ class LayerHelper(object):
# Add weight normalization to main_program
g_param
=
self
.
main_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
g_param_shape
,
**
g_param_attr
.
to_kwargs
())
dtype
=
dtype
,
shape
=
g_param_shape
,
**
g_param_attr
.
_
to_kwargs
())
v_param
=
self
.
main_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
v_param_shape
,
**
v_param_attr
.
to_kwargs
())
dtype
=
dtype
,
shape
=
v_param_shape
,
**
v_param_attr
.
_
to_kwargs
())
w_param
=
__weight_normalize
(
g_param
,
v_param
,
dim
=
attr
.
dim
)
return
w_param
...
...
@@ -296,11 +296,11 @@ class LayerHelper(object):
if
default_initializer
is
None
and
attr
.
initializer
is
None
:
if
is_bias
:
attr
.
set_default_bias_initializer
()
attr
.
_
set_default_bias_initializer
()
else
:
attr
.
set_default_param_initializer
()
attr
.
_
set_default_param_initializer
()
else
:
attr
.
set_default_initializer
(
default_initializer
)
attr
.
_
set_default_initializer
(
default_initializer
)
# If weight normalization is set, insert extra parameters and ops.
# Refer to https://arxiv.org/pdf/1602.07868.pdf
...
...
@@ -310,9 +310,9 @@ class LayerHelper(object):
return
param
self
.
startup_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
shape
,
**
attr
.
to_kwargs
(
with_initializer
=
True
))
dtype
=
dtype
,
shape
=
shape
,
**
attr
.
_
to_kwargs
(
with_initializer
=
True
))
return
self
.
main_program
.
global_block
().
create_parameter
(
dtype
=
dtype
,
shape
=
shape
,
**
attr
.
to_kwargs
())
dtype
=
dtype
,
shape
=
shape
,
**
attr
.
_
to_kwargs
())
def
get_parameter
(
self
,
name
):
param
=
self
.
main_program
.
global_block
().
var
(
name
)
...
...
python/paddle/fluid/param_attr.py
浏览文件 @
0c8f69c3
...
...
@@ -67,7 +67,7 @@ class ParamAttr(object):
self
.
gradient_clip
=
gradient_clip
self
.
model_average
=
do_model_average
def
set_default_initializer
(
self
,
initializer
):
def
_
set_default_initializer
(
self
,
initializer
):
"""
Set the default initializer, the initializer should be Constant,
Uniform, Normal, Xavier, MSRA.
...
...
@@ -88,7 +88,7 @@ class ParamAttr(object):
self
.
initializer
=
initializer
def
set_default_param_initializer
(
self
):
def
_
set_default_param_initializer
(
self
):
"""
Set the default initializer for the parameter with Xavier.
...
...
@@ -98,9 +98,9 @@ class ParamAttr(object):
Returns:
None.
"""
self
.
set_default_initializer
(
Xavier
())
self
.
_
set_default_initializer
(
Xavier
())
def
set_default_bias_initializer
(
self
):
def
_
set_default_bias_initializer
(
self
):
"""
Set the default initializer for the bias with Constant(0.0).
...
...
@@ -110,10 +110,10 @@ class ParamAttr(object):
Returns:
None.
"""
self
.
set_default_initializer
(
Constant
(
0.0
))
self
.
_
set_default_initializer
(
Constant
(
0.0
))
@
staticmethod
def
to_attr
(
arg
):
def
_
to_attr
(
arg
):
"""
Create ParamAttr[s].
...
...
@@ -131,7 +131,7 @@ class ParamAttr(object):
if
arg
is
None
:
return
ParamAttr
()
elif
isinstance
(
arg
,
list
)
or
isinstance
(
arg
,
tuple
):
return
[
ParamAttr
.
to_attr
(
a
)
for
a
in
arg
]
return
[
ParamAttr
.
_
to_attr
(
a
)
for
a
in
arg
]
elif
isinstance
(
arg
,
ParamAttr
):
return
arg
elif
isinstance
(
arg
,
str
)
or
isinstance
(
arg
,
unicode
):
...
...
@@ -141,11 +141,11 @@ class ParamAttr(object):
elif
isinstance
(
arg
,
WeightDecayRegularizer
):
return
ParamAttr
(
regularizer
=
arg
)
elif
isinstance
(
arg
,
bool
):
return
ParamAttr
.
to_attr
(
None
)
if
arg
else
False
return
ParamAttr
.
_
to_attr
(
None
)
if
arg
else
False
else
:
raise
TypeError
(
"{0} cast to ParamAttr"
.
format
(
type
(
arg
)))
def
to_kwargs
(
self
,
with_initializer
=
False
):
def
_
to_kwargs
(
self
,
with_initializer
=
False
):
"""
Returns the attributes of this parameter.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录