Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PALM
提交
c21afb28
P
PALM
项目概览
PaddlePaddle
/
PALM
通知
5
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PALM
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c21afb28
编写于
11月 24, 2019
作者:
X
Xiaoyao Xi
提交者:
GitHub
11月 24, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #27 from xixiaoyao/master
add save infermodel with train steps
上级
fffad94a
4c4807ad
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
52 addition
and
33 deletion
+52
-33
paddlepalm/mtl_controller.py
paddlepalm/mtl_controller.py
+8
-16
paddlepalm/task_instance.py
paddlepalm/task_instance.py
+44
-17
未找到文件。
paddlepalm/mtl_controller.py
浏览文件 @
c21afb28
...
...
@@ -304,19 +304,6 @@ class Controller(object):
instances
[
i
].
task_reuse_scope
=
instances
[
j
].
name
break
# parse Reader and Paradigm for each instance
for
inst
in
instances
:
reader_name
=
inst
.
config
[
'reader'
]
reader_mod
=
importlib
.
import_module
(
READER_DIR
+
'.'
+
reader_name
)
Reader
=
getattr
(
reader_mod
,
'Reader'
)
parad_name
=
inst
.
config
[
'paradigm'
]
parad_mod
=
importlib
.
import_module
(
PARADIGM_DIR
+
'.'
+
parad_name
)
Paradigm
=
getattr
(
parad_mod
,
'TaskParadigm'
)
inst
.
Reader
=
Reader
inst
.
Paradigm
=
Paradigm
self
.
instances
=
instances
self
.
mrs
=
mrs
self
.
Backbone
=
Backbone
...
...
@@ -361,7 +348,6 @@ class Controller(object):
task_attrs
=
[]
pred_task_attrs
=
[]
for
inst
in
instances
:
train_reader
=
inst
.
Reader
(
inst
.
config
,
phase
=
'train'
)
inst
.
reader
[
'train'
]
=
train_reader
train_parad
=
inst
.
Paradigm
(
inst
.
config
,
phase
=
'train'
,
backbone_config
=
bb_conf
)
...
...
@@ -605,6 +591,9 @@ class Controller(object):
global_step
+=
1
cur_task
.
cur_train_step
+=
1
if
cur_task
.
save_infermodel_every_n_steps
>
0
and
cur_task
.
cur_train_step
%
cur_task
.
save_infermodel_every_n_steps
==
0
:
cur_task
.
save
(
suffix
=
'.step'
+
str
(
cur_task
.
cur_train_step
))
if
global_step
%
main_conf
.
get
(
'print_every_n_steps'
,
5
)
==
0
:
loss
=
rt_outputs
[
cur_task
.
name
+
'/loss'
]
loss
=
np
.
mean
(
np
.
squeeze
(
loss
)).
tolist
()
...
...
@@ -635,8 +624,11 @@ class Controller(object):
assert
isinstance
(
task_instance
,
str
)
if
isinstance
(
inference_model_dir
,
str
):
assert
os
.
path
.
exists
(
inference_model_dir
),
inference_model_dir
+
" not found."
if
not
self
.
has_init_pred
and
inference_model_dir
is
None
:
raise
ValueError
(
'infer_model_path is required for prediction.'
)
# if not self.has_init_pred and inference_model_dir is None:
# raise ValueError('infer_model_path is required for prediction.')
if
inference_model_dir
is
None
:
assert
'save_path'
in
self
.
mtl_conf
,
"one of the `inference_model_dir` and 'save_path' should be set to load inference model."
inference_model_dir
=
os
.
path
.
join
(
self
.
mtl_conf
[
'save_path'
],
task_instance
,
'infer_model'
)
instance
=
None
for
inst
in
self
.
instances
:
...
...
paddlepalm/task_instance.py
浏览文件 @
c21afb28
...
...
@@ -18,16 +18,40 @@ from paddlepalm.interface import task_paradigm as base_paradigm
import
os
import
json
from
paddle
import
fluid
import
importlib
from
paddlepalm.default_settings
import
*
def
check_req_args
(
conf
,
name
):
assert
'reader'
in
conf
,
name
+
': reader is required to build TaskInstance.'
assert
'paradigm'
in
conf
,
name
+
': paradigm is required to build TaskInstance.'
assert
'train_file'
in
conf
or
'pred_file'
in
conf
,
name
+
': at least train_file or pred_file should be provided to build TaskInstance.'
class
TaskInstance
(
object
):
def
__init__
(
self
,
name
,
id
,
config
=
{}
,
verbose
=
True
):
def
__init__
(
self
,
name
,
id
,
config
,
verbose
=
True
):
self
.
_name
=
name
self
.
_config
=
config
self
.
_verbose
=
verbose
check_req_args
(
config
,
name
)
# parse Reader and Paradigm
reader_name
=
config
[
'reader'
]
reader_mod
=
importlib
.
import_module
(
READER_DIR
+
'.'
+
reader_name
)
Reader
=
getattr
(
reader_mod
,
'Reader'
)
parad_name
=
config
[
'paradigm'
]
parad_mod
=
importlib
.
import_module
(
PARADIGM_DIR
+
'.'
+
parad_name
)
Paradigm
=
getattr
(
parad_mod
,
'TaskParadigm'
)
self
.
_Reader
=
Reader
self
.
_Paradigm
=
Paradigm
self
.
_save_infermodel_path
=
os
.
path
.
join
(
self
.
_config
[
'save_path'
],
self
.
_name
,
'infer_model'
)
self
.
_save_ckpt_path
=
os
.
path
.
join
(
self
.
_config
[
'save_path'
],
'ckpt'
)
self
.
_save_infermodel_every_n_steps
=
config
.
get
(
'save_infermodel_every_n_steps'
,
-
1
)
# following flags can be fetch from instance config file
self
.
_is_target
=
config
.
get
(
'is_target'
,
True
)
...
...
@@ -56,9 +80,6 @@ class TaskInstance(object):
self
.
_pred_fetch_name_list
=
[]
self
.
_pred_fetch_var_list
=
[]
self
.
_Reader
=
None
self
.
_Paradigm
=
None
self
.
_exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
self
.
_save_protocol
=
{
...
...
@@ -87,7 +108,9 @@ class TaskInstance(object):
dirpath
=
self
.
_save_infermodel_path
+
suffix
self
.
_pred_input_varname_list
=
[
str
(
i
)
for
i
in
self
.
_pred_input_varname_list
]
fluid
.
io
.
save_inference_model
(
dirpath
,
self
.
_pred_input_varname_list
,
self
.
_pred_fetch_var_list
,
self
.
_exe
,
export_for_deployment
=
True
)
# fluid.io.save_inference_model(dirpath, self._pred_input_varname_list, self._pred_fetch_var_list, self._exe, export_for_deployment = True)
prog
=
fluid
.
default_main_program
().
clone
()
fluid
.
io
.
save_inference_model
(
dirpath
,
self
.
_pred_input_varname_list
,
self
.
_pred_fetch_var_list
,
self
.
_exe
,
prog
)
conf
=
{}
for
k
,
strv
in
self
.
_save_protocol
.
items
():
...
...
@@ -116,23 +139,23 @@ class TaskInstance(object):
def
Reader
(
self
):
return
self
.
_Reader
@
Reader
.
setter
def
Reader
(
self
,
cls
):
assert
base_reader
.
__name__
==
cls
.
__bases__
[
-
1
].
__name__
,
\
"expect: {}, receive: {}."
.
format
(
base_reader
.
__name__
,
\
cls
.
__bases__
[
-
1
].
__name__
)
self
.
_Reader
=
cls
#
@Reader.setter
#
def Reader(self, cls):
#
assert base_reader.__name__ == cls.__bases__[-1].__name__, \
#
"expect: {}, receive: {}.".format(base_reader.__name__, \
#
cls.__bases__[-1].__name__)
#
self._Reader = cls
@
property
def
Paradigm
(
self
):
return
self
.
_Paradigm
@
Paradigm
.
setter
def
Paradigm
(
self
,
cls
):
assert
base_paradigm
.
__name__
==
cls
.
__bases__
[
-
1
].
__name__
,
\
"expect: {}, receive: {}."
.
format
(
base_paradigm
.
__name__
,
\
cls
.
__bases__
[
-
1
].
__name__
)
self
.
_Paradigm
=
cls
#
@Paradigm.setter
#
def Paradigm(self, cls):
#
assert base_paradigm.__name__ == cls.__bases__[-1].__name__, \
#
"expect: {}, receive: {}.".format(base_paradigm.__name__, \
#
cls.__bases__[-1].__name__)
#
self._Paradigm = cls
@
property
def
config
(
self
):
...
...
@@ -201,6 +224,10 @@ class TaskInstance(object):
if
self
.
_verbose
:
print
(
'{}: mix_ratio is set to {}'
.
format
(
self
.
_name
,
self
.
_mix_ratio
))
@
property
def
save_infermodel_every_n_steps
(
self
):
return
self
.
_save_infermodel_every_n_steps
@
property
def
expected_train_steps
(
self
):
return
self
.
_expected_train_steps
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录