Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
3e532a78
H
hapi
项目概览
PaddlePaddle
/
hapi
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hapi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3e532a78
编写于
3月 30, 2020
作者:
L
LielinJiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix reviews
上级
237549f0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
10 deletion
+26
-10
model.py
model.py
+26
-10
未找到文件。
model.py
浏览文件 @
3e532a78
...
...
@@ -905,7 +905,7 @@ class Model(fluid.dygraph.Layer):
eval_freq (int): The frequency, in number of epochs, an evalutation
is performed.
log_freq (int): The frequency, in number of steps, the training logs
is
printed.
are
printed.
save_dir(str|None): The directory to save checkpoint during training.
If None, will not save checkpoint.
save_freq (int): The frequency, in number of epochs, to save checkpoint.
...
...
@@ -987,14 +987,22 @@ class Model(fluid.dygraph.Layer):
loader
=
train_loader
()
logs
=
self
.
_run_one_epoch
(
loader
,
cbks
,
'train'
,
metrics_name
,
epoch
=
epoch
)
cbks
.
on_epoch_end
(
epoch
,
logs
)
if
do_eval
and
epoch
%
eval_freq
==
0
:
# FIXME: adapt to DataLoader
loader
=
eval_loader
if
not
isinstance
(
eval_loader
,
Iterable
):
loader
=
eval_loader
()
eval_steps
=
len
(
loader
)
if
hasattr
(
loader
,
'__len__'
)
else
None
cbks
.
on_begin
(
'eval'
,
{
'steps'
:
eval_steps
,
'metrics_name'
:
metrics_name
})
logs
=
self
.
_run_one_epoch
(
loader
,
cbks
,
'eval'
,
metrics_name
)
cbks
.
on_end
(
'eval'
,
logs
)
cbks
.
on_end
(
'train'
,
logs
)
...
...
@@ -1017,11 +1025,11 @@ class Model(fluid.dygraph.Layer):
batch_size (int): Integer number. The batch size of train_data and eval_data.
When train_data and eval_data are both the instance of Dataloader, this
parameter will be ignored.
log_freq (int): The frequency, in number of steps, the
training
logs
is
printed.
log_freq (int): The frequency, in number of steps, the
eval
logs
are
printed.
verbose (int): The verbosity mode, should be 0, 1, or 2.
0 = silent, 1 = progress bar, 2 = one line per epoch.
num_workers (int):
t
he number of subprocess to load data, 0 for no subprocess
num_workers (int):
T
he number of subprocess to load data, 0 for no subprocess
used and loading data in main process. When train_data and eval_data are
both the instance of Dataloader, this parameter will be ignored.
callbacks (Callback|None): A list of `Callback` instances to apply
...
...
@@ -1050,12 +1058,9 @@ class Model(fluid.dygraph.Layer):
self
.
_test_dataloader
=
eval_loader
metrics_name
=
self
.
_metrics_name
()
steps
=
len
(
eval_loader
)
cbks
=
config_callbacks
(
callbacks
,
model
=
self
,
steps
=
steps
,
log_freq
=
log_freq
,
verbose
=
verbose
,
metrics
=
self
.
_metrics_name
(),
)
...
...
@@ -1063,7 +1068,14 @@ class Model(fluid.dygraph.Layer):
loader
=
eval_loader
if
not
isinstance
(
eval_loader
,
Iterable
):
loader
=
eval_loader
()
eval_steps
=
len
(
loader
)
if
hasattr
(
loader
,
'__len__'
)
else
None
cbks
.
on_begin
(
'eval'
,
{
'steps'
:
eval_steps
,
'metrics_name'
:
metrics_name
})
logs
=
self
.
_run_one_epoch
(
loader
,
cbks
,
'eval'
,
metrics_name
)
cbks
.
on_end
(
'eval'
,
logs
)
self
.
_test_dataloader
=
None
...
...
@@ -1157,9 +1169,8 @@ class Model(fluid.dygraph.Layer):
'metrics_name'
:
metrics_name
,
}
callbacks
.
on_begin
(
mode
,
logs
)
if
mode
==
'train'
:
assert
epoch
is
not
None
,
'when mode is train, '
assert
epoch
is
not
None
,
'when mode is train,
epoch must be given
'
callbacks
.
on_epoch_begin
(
epoch
)
for
step
,
data
in
enumerate
(
data_loader
):
...
...
@@ -1198,6 +1209,11 @@ class Model(fluid.dygraph.Layer):
callbacks
.
on_batch_end
(
mode
,
step
,
logs
)
self
.
_reset_metrics
()
if
mode
==
'train'
:
assert
epoch
is
not
None
,
'when mode is train, epoch must be given'
callbacks
.
on_epoch_end
(
epoch
)
return
logs
def
_reset_metrics
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录