Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
08d8a893
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
08d8a893
编写于
9月 24, 2020
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add print info of reader_cost and ips.
上级
93c4daa4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
31 deletion
+52
-31
PaddleCV/image_classification/train.py
PaddleCV/image_classification/train.py
+35
-21
PaddleCV/image_classification/utils/utility.py
PaddleCV/image_classification/utils/utility.py
+17
-10
未找到文件。
PaddleCV/image_classification/train.py
浏览文件 @
08d8a893
...
...
@@ -34,22 +34,22 @@ logging.basicConfig(level=logging.INFO)
logger
=
logging
.
getLogger
(
__name__
)
class
Time
CostAverage
(
object
):
class
Time
Averager
(
object
):
def
__init__
(
self
):
self
.
reset
()
def
reset
(
self
):
self
.
cnt
=
0
self
.
total_time
=
0
self
.
_
cnt
=
0
self
.
_
total_time
=
0
def
record
(
self
,
usetime
):
self
.
cnt
+=
1
self
.
total_time
+=
usetime
self
.
_
cnt
+=
1
self
.
_
total_time
+=
usetime
def
get_average
(
self
):
if
self
.
cnt
==
0
:
if
self
.
_
cnt
==
0
:
return
0
return
self
.
total_time
/
self
.
cnt
return
self
.
_total_time
/
self
.
_
cnt
def
build_program
(
is_train
,
main_prog
,
startup_prog
,
args
):
...
...
@@ -244,15 +244,15 @@ def train(args):
compiled_train_prog
=
best_strategy_compiled
(
args
,
train_prog
,
train_fetch_vars
[
0
],
exe
)
batch_cost_avg
=
TimeCostAverage
()
#NOTE: this for benchmark
total_batch_num
=
0
batch_cost_averager
=
TimeAverager
()
reader_cost_averager
=
TimeAverager
()
for
pass_id
in
range
(
args
.
num_epochs
):
if
num_trainers
>
1
and
not
args
.
use_dali
:
imagenet_reader
.
set_shuffle_seed
(
pass_id
+
(
args
.
random_seed
if
args
.
random_seed
else
0
))
train_batch_id
=
0
train_batch_time_record
=
[]
train_batch_metrics_record
=
[]
...
...
@@ -262,33 +262,47 @@ def train(args):
if
args
.
validate
:
test_iter
=
test_data_loader
()
t1
=
time
.
time
()
batch_start
=
time
.
time
()
for
batch
in
train_iter
:
#NOTE: this is for benchmark
if
args
.
max_iter
and
total_batch_num
==
args
.
max_iter
:
return
reader_cost_averager
.
record
(
time
.
time
()
-
batch_start
)
train_batch_metrics
=
exe
.
run
(
compiled_train_prog
,
feed
=
batch
,
fetch_list
=
train_fetch_list
)
t2
=
time
.
time
()
train_batch_elapse
=
t2
-
t1
train_batch_time_record
.
append
(
train_batch_elapse
)
batch_cost_avg
.
record
(
train_batch_elapse
)
train_batch_metrics_avg
=
np
.
mean
(
np
.
array
(
train_batch_metrics
),
axis
=
1
)
train_batch_metrics_record
.
append
(
train_batch_metrics_avg
)
# Record the time for ce and benchmark
train_batch_elapse
=
time
.
time
()
-
batch_start
train_batch_time_record
.
append
(
train_batch_elapse
)
batch_cost_averager
.
record
(
train_batch_elapse
)
if
trainer_id
==
0
:
print_info
(
"batch"
,
train_batch_metrics_avg
,
batch_cost_avg
.
get_average
(),
pass_id
,
train_batch_id
,
args
.
print_step
)
ips
=
float
(
args
.
batch_size
)
/
batch_cost_averager
.
get_average
()
print_info
(
"batch"
,
train_batch_metrics_avg
,
batch_cost_averager
.
get_average
(),
pass_id
,
train_batch_id
,
args
.
print_step
,
reader_cost
=
reader_cost_averager
.
get_average
(),
ips
=
ips
)
sys
.
stdout
.
flush
()
if
train_batch_id
%
args
.
print_step
==
0
:
batch_cost_avg
.
reset
()
batch_cost_averager
.
reset
()
reader_cost_averager
.
reset
()
train_batch_id
+=
1
t1
=
time
.
time
()
#NOTE: this for benchmark profiler
total_batch_num
=
total_batch_num
+
1
batch_start
=
time
.
time
()
#NOTE: this for benchmark profiler
if
args
.
is_profiler
and
pass_id
==
0
and
train_batch_id
==
args
.
print_step
:
profiler
.
start_profiler
(
"All"
)
elif
args
.
is_profiler
and
pass_id
==
0
and
train_batch_id
==
args
.
print_step
+
5
:
...
...
PaddleCV/image_classification/utils/utility.py
浏览文件 @
08d8a893
...
...
@@ -420,7 +420,9 @@ def print_info(info_mode,
batch_id
=
0
,
print_step
=
1
,
device_num
=
1
,
class_dim
=
5
):
class_dim
=
5
,
reader_cost
=
None
,
ips
=
None
):
"""print function
Args:
...
...
@@ -433,31 +435,35 @@ def print_info(info_mode,
"""
#XXX: Use specific name to choose pattern, not the length of metrics.
if
info_mode
==
"batch"
:
time_info_str
=
"batch_cost %.5f sec"
%
time_info
if
reader_cost
:
time_info_str
+=
", reader_cost %.5f sec"
%
reader_cost
if
ips
:
time_info_str
+=
", ips %.5f images/sec"
%
ips
if
batch_id
%
print_step
==
0
:
#if isinstance(metrics,np.ndarray):
# train and mixup output
if
len
(
metrics
)
==
2
:
loss
,
lr
=
metrics
logger
.
info
(
"[Pass {0}, train batch {1}]
\t
loss {2}, lr {3},
elapse
{4}"
.
"[Pass {0}, train batch {1}]
\t
loss {2}, lr {3}, {4}"
.
format
(
pass_id
,
batch_id
,
"%.5f"
%
loss
,
"%.5f"
%
lr
,
"%2.4f sec"
%
time_info
))
time_info_str
))
# train and no mixup output
elif
len
(
metrics
)
==
4
:
loss
,
acc1
,
acc5
,
lr
=
metrics
logger
.
info
(
"[Pass {0}, train batch {1}]
\t
loss {2}, acc1 {3}, acc{7} {4}, lr {5},
elapse
{6}"
.
"[Pass {0}, train batch {1}]
\t
loss {2}, acc1 {3}, acc{7} {4}, lr {5}, {6}"
.
format
(
pass_id
,
batch_id
,
"%.5f"
%
loss
,
"%.5f"
%
acc1
,
"%.5f"
%
acc5
,
"%.5f"
%
lr
,
"%2.4f sec"
%
time_info
,
"%.5f"
%
acc5
,
"%.5f"
%
lr
,
time_info_str
,
min
(
class_dim
,
5
)))
# test output
elif
len
(
metrics
)
==
3
:
loss
,
acc1
,
acc5
=
metrics
logger
.
info
(
"[Pass {0}, test batch {1}]
\t
loss {2}, acc1 {3}, acc{6} {4},
elapse
{5}"
.
"[Pass {0}, test batch {1}]
\t
loss {2}, acc1 {3}, acc{6} {4}, {5}"
.
format
(
pass_id
,
batch_id
,
"%.5f"
%
loss
,
"%.5f"
%
acc1
,
"%.5f"
%
acc5
,
"%2.4f sec"
%
time_info
,
min
(
class_dim
,
5
)))
"%.5f"
%
acc5
,
time_info_str
,
min
(
class_dim
,
5
)))
else
:
raise
Exception
(
"length of metrics {} is not implemented, It maybe caused by wrong format of build_program_output"
.
...
...
@@ -525,8 +531,9 @@ def best_strategy_compiled(args,
fluid
.
require_version
(
min_version
=
'1.7.0'
)
build_strategy
.
fuse_bn_act_ops
=
args
.
fuse_bn_act_ops
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle version 1.7.0 or higher is "
"required when you want to fuse batch_norm and activation_op."
)
logger
.
info
(
"PaddlePaddle version 1.7.0 or higher is "
"required when you want to fuse batch_norm and activation_op."
)
build_strategy
.
fuse_elewise_add_act_ops
=
args
.
fuse_elewise_add_act_ops
exec_strategy
=
fluid
.
ExecutionStrategy
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录