Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
afeixing77
Paddle
提交
eb7d8754
P
Paddle
项目概览
afeixing77
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eb7d8754
编写于
5月 18, 2018
作者:
Q
Qiao Longfei
提交者:
daminglu
5月 17, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add trainer.stop and fix a bug for train_by_parallel_executor (#10762)
上级
54ae8e45
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
22 addition
and
17 deletion
+22
-17
python/paddle/fluid/tests/book/high-level-api/fit_a_line/test_fit_a_line.py
...d/tests/book/high-level-api/fit_a_line/test_fit_a_line.py
+12
-14
python/paddle/fluid/trainer.py
python/paddle/fluid/trainer.py
+10
-3
未找到文件。
python/paddle/fluid/tests/book/high-level-api/fit_a_line/test_fit_a_line.py
浏览文件 @
eb7d8754
...
...
@@ -57,22 +57,20 @@ def train(use_cuda, train_program, save_dirname):
optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
0.001
))
def
event_handler
(
event
):
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
event
.
step
==
10
:
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
[
'x'
,
'y'
])
print
test_metrics
'''
...
['25.768919467926025']
['15.343549569447836']
...
'''
if
float
(
test_metrics
[
0
])
<
20.0
:
if
save_dirname
is
not
None
:
trainer
.
save_params
(
save_dirname
)
return
trainer
.
stop
()
trainer
.
train
(
reader
=
train_reader
,
...
...
python/paddle/fluid/trainer.py
浏览文件 @
eb7d8754
...
...
@@ -100,6 +100,7 @@ class Trainer(object):
param_path
=
None
,
place
=
None
,
parallel
=
False
):
self
.
__stop
=
False
self
.
parallel
=
parallel
# 1. we need to generate a framework.Program by calling
# program_func. Reference: fluid.program_guard in
...
...
@@ -210,6 +211,12 @@ class Trainer(object):
'TRAINING_ROLE environment variable must be either TRAINER or PSERVER'
)
def
stop
(
self
):
"""
stop training
"""
self
.
__stop
=
True
def
train
(
self
,
num_epochs
,
event_handler
,
reader
=
None
,
feed_order
=
None
):
"""
Train the model.
...
...
@@ -289,6 +296,8 @@ class Trainer(object):
for
epoch_id
in
range
(
num_epochs
):
event_handler
(
BeginEpochEvent
(
epoch_id
))
for
step_id
,
data
in
enumerate
(
reader
()):
if
self
.
__stop
:
return
begin_event
=
BeginStepEvent
(
epoch_id
,
step_id
)
event_handler
(
begin_event
)
if
begin_event
.
fetch_metrics
:
...
...
@@ -327,9 +336,7 @@ class Trainer(object):
feeder
=
data_feeder
.
DataFeeder
(
feed_list
=
feed_var_list
,
place
=
self
.
place
)
reader
=
feeder
.
decorate_reader
(
reader
,
multi_devices
=
True
)
for
epoch_id
in
range
(
num_epochs
):
self
.
_train_by_any_executor
(
event_handler
,
pe
,
num_epochs
,
reader
)
self
.
_train_by_any_executor
(
event_handler
,
pe
,
num_epochs
,
reader
)
def
_get_parallel_executor
(
self
):
return
getattr
(
self
,
'parallel_executor'
,
None
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录