Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
bfcd53da
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bfcd53da
编写于
4月 10, 2020
作者:
T
tangwei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code fix
上级
af3dad94
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
46 deletion
+45
-46
fleetrec/models/base.py
fleetrec/models/base.py
+45
-46
未找到文件。
fleetrec/models/base.py
浏览文件 @
bfcd53da
...
@@ -75,13 +75,6 @@ class Model(object):
...
@@ -75,13 +75,6 @@ class Model(object):
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
"""R
"""R
"""
"""
self
.
_config
=
config
self
.
_name
=
config
[
'name'
]
f
=
open
(
config
[
'layer_file'
],
'r'
)
self
.
_build_nodes
=
yaml
.
safe_load
(
f
.
read
())
self
.
_build_phase
=
[
'input'
,
'param'
,
'summary'
,
'layer'
]
self
.
_build_param
=
{
'layer'
:
{},
'inner_layer'
:
{},
'layer_extend'
:
{},
'model'
:
{}}
self
.
_inference_meta
=
{
'dependency'
:
{},
'params'
:
{}}
self
.
_cost
=
None
self
.
_cost
=
None
self
.
_metrics
=
{}
self
.
_metrics
=
{}
self
.
_data_var
=
[]
self
.
_data_var
=
[]
...
@@ -130,44 +123,6 @@ class Model(object):
...
@@ -130,44 +123,6 @@ class Model(object):
"""
"""
pass
pass
def
inference_params
(
self
,
inference_layer
):
"""
get params name for inference_layer
Args:
inference_layer(str): layer for inference
Return:
params(list): params name list that for inference layer
"""
layer
=
inference_layer
if
layer
in
self
.
_inference_meta
[
'params'
]:
return
self
.
_inference_meta
[
'params'
][
layer
]
self
.
_inference_meta
[
'params'
][
layer
]
=
[]
self
.
_inference_meta
[
'dependency'
][
layer
]
=
self
.
get_dependency
(
self
.
_build_param
[
'inner_layer'
],
layer
)
for
node
in
self
.
_build_nodes
[
'layer'
]:
if
node
[
'name'
]
not
in
self
.
_inference_meta
[
'dependency'
][
layer
]:
continue
if
'inference_param'
in
self
.
_build_param
[
'layer_extend'
][
node
[
'name'
]]:
self
.
_inference_meta
[
'params'
][
layer
]
+=
\
self
.
_build_param
[
'layer_extend'
][
node
[
'name'
]][
'inference_param'
][
'params'
]
return
self
.
_inference_meta
[
'params'
][
layer
]
def
get_dependency
(
self
,
layer_graph
,
dest_layer
):
"""
get model of dest_layer depends on
Args:
layer_graph(dict) : all model in graph
Return:
depend_layers(list) : sub-graph model for calculate dest_layer
"""
dependency_list
=
[]
if
dest_layer
in
layer_graph
:
dependencys
=
copy
.
deepcopy
(
layer_graph
[
dest_layer
][
'input'
])
dependency_list
=
copy
.
deepcopy
(
dependencys
)
for
dependency
in
dependencys
:
dependency_list
=
dependency_list
+
self
.
get_dependency
(
layer_graph
,
dependency
)
return
list
(
set
(
dependency_list
))
class
YamlModel
(
Model
):
class
YamlModel
(
Model
):
"""R
"""R
...
@@ -177,7 +132,13 @@ class YamlModel(Model):
...
@@ -177,7 +132,13 @@ class YamlModel(Model):
"""R
"""R
"""
"""
Model
.
__init__
(
self
,
config
)
Model
.
__init__
(
self
,
config
)
pass
self
.
_config
=
config
self
.
_name
=
config
[
'name'
]
f
=
open
(
config
[
'layer_file'
],
'r'
)
self
.
_build_nodes
=
yaml
.
safe_load
(
f
.
read
())
self
.
_build_phase
=
[
'input'
,
'param'
,
'summary'
,
'layer'
]
self
.
_build_param
=
{
'layer'
:
{},
'inner_layer'
:
{},
'layer_extend'
:
{},
'model'
:
{}}
self
.
_inference_meta
=
{
'dependency'
:
{},
'params'
:
{}}
def
build_model
(
self
):
def
build_model
(
self
):
"""R
"""R
...
@@ -289,3 +250,41 @@ class YamlModel(Model):
...
@@ -289,3 +250,41 @@ class YamlModel(Model):
program
,
vars
=
params_var_list
,
filename
=
params_file_name
)
program
,
vars
=
params_var_list
,
filename
=
params_file_name
)
else
:
else
:
fluid
.
io
.
save_vars
(
executor
,
params_file_name
,
program
,
vars
=
params_var_list
)
fluid
.
io
.
save_vars
(
executor
,
params_file_name
,
program
,
vars
=
params_var_list
)
def
inference_params
(
self
,
inference_layer
):
"""
get params name for inference_layer
Args:
inference_layer(str): layer for inference
Return:
params(list): params name list that for inference layer
"""
layer
=
inference_layer
if
layer
in
self
.
_inference_meta
[
'params'
]:
return
self
.
_inference_meta
[
'params'
][
layer
]
self
.
_inference_meta
[
'params'
][
layer
]
=
[]
self
.
_inference_meta
[
'dependency'
][
layer
]
=
self
.
get_dependency
(
self
.
_build_param
[
'inner_layer'
],
layer
)
for
node
in
self
.
_build_nodes
[
'layer'
]:
if
node
[
'name'
]
not
in
self
.
_inference_meta
[
'dependency'
][
layer
]:
continue
if
'inference_param'
in
self
.
_build_param
[
'layer_extend'
][
node
[
'name'
]]:
self
.
_inference_meta
[
'params'
][
layer
]
+=
\
self
.
_build_param
[
'layer_extend'
][
node
[
'name'
]][
'inference_param'
][
'params'
]
return
self
.
_inference_meta
[
'params'
][
layer
]
def
get_dependency
(
self
,
layer_graph
,
dest_layer
):
"""
get model of dest_layer depends on
Args:
layer_graph(dict) : all model in graph
Return:
depend_layers(list) : sub-graph model for calculate dest_layer
"""
dependency_list
=
[]
if
dest_layer
in
layer_graph
:
dependencys
=
copy
.
deepcopy
(
layer_graph
[
dest_layer
][
'input'
])
dependency_list
=
copy
.
deepcopy
(
dependencys
)
for
dependency
in
dependencys
:
dependency_list
=
dependency_list
+
self
.
get_dependency
(
layer_graph
,
dependency
)
return
list
(
set
(
dependency_list
))
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录