Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
fa94261b
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
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看板
提交
fa94261b
编写于
7月 31, 2018
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avoid duplicated init op for one parameter
上级
56b50ee4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
0 deletion
+28
-0
python/paddle/fluid/initializer.py
python/paddle/fluid/initializer.py
+28
-0
未找到文件。
python/paddle/fluid/initializer.py
浏览文件 @
fa94261b
...
...
@@ -62,6 +62,13 @@ def init_on_cpu():
_force_init_on_cpu_
=
pre_state
def
_is_inited_by
(
block
,
var
,
init_op_type
):
for
op
in
block
.
ops
:
if
var
.
name
in
op
.
output_arg_names
and
op
.
type
==
init_op_type
:
return
op
return
None
class
Initializer
(
object
):
"""Base class for variable initializers
...
...
@@ -147,6 +154,9 @@ class ConstantInitializer(Initializer):
"""
assert
isinstance
(
var
,
framework
.
Variable
)
assert
isinstance
(
block
,
framework
.
Block
)
init_op
=
_is_inited_by
(
block
,
var
,
'uniform_random'
)
if
init_op
is
not
None
:
return
init_op
# Initialization Ops should be prepended and not appended
op
=
block
.
_prepend_op
(
type
=
"fill_constant"
,
...
...
@@ -199,6 +209,9 @@ class UniformInitializer(Initializer):
"""
assert
isinstance
(
var
,
framework
.
Variable
)
assert
isinstance
(
block
,
framework
.
Block
)
init_op
=
_is_inited_by
(
block
,
var
,
'uniform_random'
)
if
init_op
is
not
None
:
return
init_op
# Initialization Ops should be prepended and not appended
if
self
.
_seed
==
0
:
self
.
_seed
=
block
.
program
.
random_seed
...
...
@@ -253,6 +266,9 @@ class NormalInitializer(Initializer):
"""
assert
isinstance
(
var
,
framework
.
Variable
)
assert
isinstance
(
block
,
framework
.
Block
)
init_op
=
_is_inited_by
(
block
,
var
,
'uniform_random'
)
if
init_op
is
not
None
:
return
init_op
# Initialization Ops should be prepended and not appended
if
self
.
_seed
==
0
:
self
.
_seed
=
block
.
program
.
random_seed
...
...
@@ -335,6 +351,10 @@ class XavierInitializer(Initializer):
"""
assert
isinstance
(
var
,
framework
.
Variable
)
assert
isinstance
(
block
,
framework
.
Block
)
init_op
=
_is_inited_by
(
block
,
var
,
'uniform_random'
)
if
init_op
is
not
None
:
return
init_op
f_in
,
f_out
=
self
.
_compute_fans
(
var
)
# If fan_in and fan_out are passed, use them
...
...
@@ -434,6 +454,10 @@ class MSRAInitializer(Initializer):
"""
assert
isinstance
(
var
,
framework
.
Variable
)
assert
isinstance
(
block
,
framework
.
Block
)
init_op
=
_is_inited_by
(
block
,
var
,
'uniform_random'
)
if
init_op
is
not
None
:
return
init_op
f_in
,
f_out
=
self
.
_compute_fans
(
var
)
# If fan_in is passed, use it
...
...
@@ -532,6 +556,10 @@ class BilinearInitializer(Initializer):
if
not
isinstance
(
block
,
framework
.
Block
):
raise
ValueError
(
"block must be framework.Block."
)
init_op
=
_is_inited_by
(
block
,
var
,
'uniform_random'
)
if
init_op
is
not
None
:
return
init_op
shape
=
var
.
shape
if
len
(
shape
)
!=
4
:
raise
ValueError
(
"the length of shape must be 4."
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录