Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0cb8a666
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看板
提交
0cb8a666
编写于
5月 26, 2017
作者:
X
xuwei06
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix style
上级
7d0355cd
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
20 addition
and
20 deletion
+20
-20
python/paddle/v2/layer.py
python/paddle/v2/layer.py
+20
-20
未找到文件。
python/paddle/v2/layer.py
浏览文件 @
0cb8a666
...
...
@@ -40,6 +40,7 @@ from paddle.proto.ModelConfig_pb2 import ModelConfig, SubModelConfig
__all__
=
[
'data'
,
'parse_network'
]
__layer_map__
=
{}
def
__wrap__
(
f
):
def
wrapped
(
*
args
,
**
xargs
):
out
=
f
(
*
args
,
**
xargs
)
...
...
@@ -53,6 +54,7 @@ def __wrap__(f):
return
wrapped
def
__need_to_keep__
(
name
):
if
name
in
[
'StaticInput'
,
'LayerType'
,
'layer_support'
]:
return
False
...
...
@@ -99,6 +101,7 @@ def __data_layer__(name, type, **kwargs):
l
.
data_type
=
type
return
l
data
=
__wrap__
(
__data_layer__
)
LayerV2
=
v1_layers
.
LayerOutput
...
...
@@ -107,6 +110,7 @@ LayerV2 = v1_layers.LayerOutput
def
__get_used_layers__
(
output_layers
,
extra_layers
=
None
):
layer_names
=
set
()
parents
=
{}
def
add_parent
(
child
,
parent
):
if
child
in
parents
:
parents
[
child
].
append
(
parent
)
...
...
@@ -181,28 +185,25 @@ def __get_used_evaluators__(layer_names):
return
evaluator_names
def
__trim_submodel__
(
old_submodel
,
layer_names
,
input_layer_names
,
output_layer_names
,
evaluator_names
):
def
__trim_submodel__
(
old_submodel
,
layer_names
,
input_layer_names
,
output_layer_names
,
evaluator_names
):
submodel
=
SubModelConfig
()
submodel
.
name
=
old_submodel
.
name
submodel
.
layer_names
.
extend
(
filter
(
lambda
x
:
x
in
layer_names
,
old_submodel
.
layer_names
))
submodel
.
input_layer_names
.
extend
(
filter
(
lambda
x
:
x
in
input_layer_names
,
submodel
.
layer_names
))
submodel
.
output_layer_names
.
extend
(
filter
(
lambda
x
:
x
in
output_layer_names
,
submodel
.
layer_names
))
submodel
.
evaluator_names
.
extend
(
filter
(
lambda
x
:
x
in
evaluator_names
,
old_submodel
.
evaluator_names
))
submodel
.
layer_names
.
extend
(
filter
(
lambda
x
:
x
in
layer_names
,
old_submodel
.
layer_names
))
submodel
.
input_layer_names
.
extend
(
filter
(
lambda
x
:
x
in
input_layer_names
,
submodel
.
layer_names
))
submodel
.
output_layer_names
.
extend
(
filter
(
lambda
x
:
x
in
output_layer_names
,
submodel
.
layer_names
))
submodel
.
evaluator_names
.
extend
(
filter
(
lambda
x
:
x
in
evaluator_names
,
old_submodel
.
evaluator_names
))
submodel
.
is_recurrent_layer_group
=
old_submodel
.
is_recurrent_layer_group
submodel
.
reversed
=
old_submodel
.
reversed
submodel
.
memories
.
extend
(
filter
(
lambda
x
:
x
.
link_name
in
layer_names
,
old_submodel
.
memories
))
submodel
.
memories
.
extend
(
filter
(
lambda
x
:
x
.
link_name
in
layer_names
,
old_submodel
.
memories
))
target_inlinkid
=
(
old_submodel
.
target_inlinkid
if
old_submodel
.
HasField
(
'target_inlinkid'
)
else
-
1
)
in_links
=
[]
...
...
@@ -213,8 +214,8 @@ def __trim_submodel__(old_submodel,
target_inlinkid
=
len
(
in_links
)
-
1
submodel
.
in_links
.
extend
(
in_links
)
submodel
.
out_links
.
extend
(
filter
(
lambda
x
:
x
.
link_name
in
layer_names
,
old_submodel
.
out_links
))
submodel
.
out_links
.
extend
(
filter
(
lambda
x
:
x
.
link_name
in
layer_names
,
old_submodel
.
out_links
))
if
old_submodel
.
HasField
(
'generator'
):
submodel
.
generator
.
CopyFrom
(
old_submodel
.
generator
)
...
...
@@ -264,9 +265,8 @@ def parse_network(output_layers, extra_layers=None):
for
s
in
cp
.
g_config
.
model_config
.
sub_models
:
if
s
.
name
in
submodel_names
:
s
=
__trim_submodel__
(
s
,
layer_names
,
input_layer_names
,
output_layer_names
,
evaluator_names
)
s
=
__trim_submodel__
(
s
,
layer_names
,
input_layer_names
,
output_layer_names
,
evaluator_names
)
model_config
.
sub_models
.
extend
([
s
])
return
model_config
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录