Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PALM
提交
0414a874
P
PALM
项目概览
PaddlePaddle
/
PALM
通知
4
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看板
提交
0414a874
编写于
2月 05, 2020
作者:
W
wangxiao1021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs
上级
9e99e1de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
12 addition
and
17 deletion
+12
-17
examples/multi-task/run.py
examples/multi-task/run.py
+1
-1
paddlepalm/multihead_trainer.py
paddlepalm/multihead_trainer.py
+2
-0
paddlepalm/trainer.py
paddlepalm/trainer.py
+9
-16
未找到文件。
examples/multi-task/run.py
浏览文件 @
0414a874
...
@@ -78,6 +78,6 @@ if __name__ == '__main__':
...
@@ -78,6 +78,6 @@ if __name__ == '__main__':
# step 8-2*: set saver to save model
# step 8-2*: set saver to save model
save_steps
=
int
(
n_steps
-
batch_size
)
//
2
save_steps
=
int
(
n_steps
-
batch_size
)
//
2
# save_steps = 10
# save_steps = 10
trainer
.
set_saver
(
save_path
=
save_path
,
save_steps
=
save_steps
,
save_type
=
save_type
,
is_multi
=
True
)
trainer
.
set_saver
(
save_path
=
save_path
,
save_steps
=
save_steps
,
save_type
=
save_type
)
# step 8-3: start training
# step 8-3: start training
trainer
.
train
(
print_steps
=
print_steps
)
trainer
.
train
(
print_steps
=
print_steps
)
\ No newline at end of file
paddlepalm/multihead_trainer.py
浏览文件 @
0414a874
...
@@ -82,7 +82,9 @@ class MultiHeadTrainer(Trainer):
...
@@ -82,7 +82,9 @@ class MultiHeadTrainer(Trainer):
def
get_loss
(
i
):
def
get_loss
(
i
):
head
=
head_dict
[
self
.
_trainers
[
i
].
name
]
head
=
head_dict
[
self
.
_trainers
[
i
].
name
]
self
.
_trainers
[
i
].
_lock_prog
=
True
loss_var
=
self
.
_trainers
[
i
].
build_forward
(
backbone
,
head
)
loss_var
=
self
.
_trainers
[
i
].
build_forward
(
backbone
,
head
)
self
.
_trainers
[
i
].
_lock_prog
=
False
return
loss_var
return
loss_var
task_fns
=
{
i
:
lambda
i
=
i
:
get_loss
(
i
)
for
i
in
range
(
len
(
self
.
_trainers
))}
task_fns
=
{
i
:
lambda
i
=
i
:
get_loss
(
i
)
for
i
in
range
(
len
(
self
.
_trainers
))}
...
...
paddlepalm/trainer.py
浏览文件 @
0414a874
...
@@ -162,8 +162,10 @@ class Trainer(object):
...
@@ -162,8 +162,10 @@ class Trainer(object):
train_prog
=
fluid
.
Program
()
train_prog
=
fluid
.
Program
()
train_init_prog
=
fluid
.
Program
()
train_init_prog
=
fluid
.
Program
()
self
.
_train_prog
=
train_prog
if
not
self
.
_lock_prog
:
self
.
_train_init_prog
=
train_init_prog
self
.
_train_prog
=
train_prog
self
.
_train_init_prog
=
train_init_prog
if
not
self
.
_lock_prog
:
if
not
self
.
_lock_prog
:
with
fluid
.
program_guard
(
train_prog
,
train_init_prog
):
with
fluid
.
program_guard
(
train_prog
,
train_init_prog
):
net_inputs
=
reader_helper
.
create_net_inputs
(
input_attrs
,
async
=
False
)
net_inputs
=
reader_helper
.
create_net_inputs
(
input_attrs
,
async
=
False
)
...
@@ -505,7 +507,7 @@ class Trainer(object):
...
@@ -505,7 +507,7 @@ class Trainer(object):
convert
=
convert
,
convert
=
convert
,
main_program
=
self
.
_train_init_prog
)
main_program
=
self
.
_train_init_prog
)
def
set_saver
(
self
,
save_path
,
save_steps
,
save_type
=
'ckpt'
,
is_multi
=
False
):
def
set_saver
(
self
,
save_path
,
save_steps
,
save_type
=
'ckpt'
):
"""
"""
create a build-in saver into trainer. A saver will automatically save checkpoint or predict model every `save_steps` training steps.
create a build-in saver into trainer. A saver will automatically save checkpoint or predict model every `save_steps` training steps.
...
@@ -542,20 +544,11 @@ class Trainer(object):
...
@@ -542,20 +544,11 @@ class Trainer(object):
if
(
self
.
_save_predict
or
self
.
_save_ckpt
)
and
self
.
_cur_train_step
%
save_steps
==
0
:
if
(
self
.
_save_predict
or
self
.
_save_ckpt
)
and
self
.
_cur_train_step
%
save_steps
==
0
:
if
self
.
_save_predict
:
if
self
.
_save_predict
:
if
is_multi
:
self
.
_save
(
save_path
,
suffix
=
'pred.step'
+
str
(
self
.
_cur_train_step
))
self
.
_save
(
save_path
,
suffix
=
'-pred.step'
+
str
(
self
.
_cur_train_step
))
print
(
'predict model has been saved at '
+
os
.
path
.
join
(
save_path
,
'pred.step'
+
str
(
self
.
_cur_train_step
)))
print
(
'predict model has been saved at '
+
os
.
path
.
join
(
save_path
,
'pred.step'
+
str
(
self
.
_cur_train_step
)))
else
:
self
.
_save
(
save_path
,
suffix
=
'pred.step'
+
str
(
self
.
_cur_train_step
))
print
(
'predict model has been saved at '
+
os
.
path
.
join
(
save_path
,
'pred.step'
+
str
(
self
.
_cur_train_step
)))
if
self
.
_save_ckpt
:
if
self
.
_save_ckpt
:
print
(
self
.
_train_prog
)
fluid
.
io
.
save_persistables
(
self
.
_exe
,
os
.
path
.
join
(
save_path
,
'ckpt.step'
+
str
(
self
.
_cur_train_step
)),
self
.
_train_prog
)
if
is_multi
:
print
(
'checkpoint has been saved at '
+
os
.
path
.
join
(
save_path
,
'ckpt.step'
+
str
(
self
.
_cur_train_step
)))
fluid
.
io
.
save_persistables
(
self
.
_exe
,
os
.
path
.
join
(
save_path
,
'ckpt.step'
+
str
(
self
.
_cur_train_step
)),
self
.
_train_prog
)
print
(
'checkpoint has been saved at '
+
os
.
path
.
join
(
save_path
,
'ckpt.step'
+
str
(
self
.
_cur_train_step
)))
else
:
fluid
.
io
.
save_persistables
(
self
.
_exe
,
os
.
path
.
join
(
save_path
,
'ckpt.step'
+
str
(
self
.
_cur_train_step
)),
self
.
_train_prog
)
print
(
'checkpoint has been saved at '
+
os
.
path
.
join
(
save_path
,
'ckpt.step'
+
str
(
self
.
_cur_train_step
)))
return
True
return
True
else
:
else
:
return
False
return
False
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录