Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
ee102078
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ee102078
编写于
11月 05, 2020
作者:
L
littletomatodonkey
提交者:
GitHub
11月 05, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix log benchmark (#369)
fix log benchmark
上级
d4b1f6af
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
38 deletion
+39
-38
ppcls/utils/misc.py
ppcls/utils/misc.py
+8
-5
tools/program.py
tools/program.py
+29
-32
tools/train.py
tools/train.py
+2
-1
未找到文件。
ppcls/utils/misc.py
浏览文件 @
ee102078
...
...
@@ -20,9 +20,10 @@ class AverageMeter(object):
Computes and stores the average and current value
"""
def
__init__
(
self
,
name
=
''
,
fmt
=
'f'
,
need_avg
=
True
):
def
__init__
(
self
,
name
=
''
,
fmt
=
'f'
,
postfix
=
""
,
need_avg
=
True
):
self
.
name
=
name
self
.
fmt
=
fmt
self
.
postfix
=
postfix
self
.
need_avg
=
need_avg
self
.
reset
()
...
...
@@ -42,18 +43,20 @@ class AverageMeter(object):
@
property
def
total
(
self
):
return
'{self.name}_sum: {self.sum:{self.fmt}}'
.
format
(
self
=
self
)
return
'{self.name}_sum: {self.sum:{self.fmt}}{self.postfix}'
.
format
(
self
=
self
)
@
property
def
total_minute
(
self
):
return
'{self.name}_sum: {s:{self.fmt}} min'
.
format
(
return
'{self.name}_sum: {s:{self.fmt}}
{self.postfix}
min'
.
format
(
s
=
self
.
sum
/
60
,
self
=
self
)
@
property
def
mean
(
self
):
return
'{self.name}_avg: {self.avg:{self.fmt}}'
.
format
(
return
'{self.name}_avg: {self.avg:{self.fmt}}
{self.postfix}
'
.
format
(
self
=
self
)
if
self
.
need_avg
else
''
@
property
def
value
(
self
):
return
'{self.name}: {self.val:{self.fmt}}'
.
format
(
self
=
self
)
return
'{self.name}: {self.val:{self.fmt}}{self.postfix}'
.
format
(
self
=
self
)
tools/program.py
浏览文件 @
ee102078
...
...
@@ -36,24 +36,6 @@ from ppcls.utils.misc import AverageMeter
from
ppcls.utils
import
logger
def
create_dataloader
():
"""
Create a dataloader with model input variables
Args:
feeds(dict): dict of model input variables
Returns:
dataloader(paddle dataloader):
"""
trainer_num
=
int
(
os
.
environ
.
get
(
'PADDLE_TRAINERS_NUM'
,
1
))
capacity
=
64
if
trainer_num
==
1
else
8
dataloader
=
paddle
.
io
.
DataLoader
.
from_generator
(
capacity
=
capacity
,
use_double_buffer
=
True
,
iterable
=
True
)
return
dataloader
def
create_model
(
architecture
,
classes_num
):
"""
Create a model
...
...
@@ -275,16 +257,23 @@ def run(dataloader,
use_mix
=
config
.
get
(
"use_mix"
,
False
)
and
mode
==
"train"
metric_list
=
[
(
"loss"
,
AverageMeter
(
'loss'
,
'7.5f'
)),
(
"loss"
,
AverageMeter
(
'loss'
,
'7.5f'
,
postfix
=
","
)),
(
"lr"
,
AverageMeter
(
'lr'
,
'f'
,
need_avg
=
False
)),
(
"batch_time"
,
AverageMeter
(
'elapse'
,
'.7f'
)),
(
"reader_time"
,
AverageMeter
(
'reader '
,
'.7f'
)),
'lr'
,
'f'
,
postfix
=
","
,
need_avg
=
False
)),
(
"batch_time"
,
AverageMeter
(
'batch_cost'
,
'.5f'
,
postfix
=
" s,"
)),
(
"reader_time"
,
AverageMeter
(
'reader_cost'
,
'.5f'
,
postfix
=
" s,"
)),
]
if
not
use_mix
:
topk_name
=
'top{}'
.
format
(
config
.
topk
)
metric_list
.
insert
(
1
,
(
topk_name
,
AverageMeter
(
topk_name
,
'.5f'
)))
metric_list
.
insert
(
1
,
(
"top1"
,
AverageMeter
(
"top1"
,
'.5f'
)))
metric_list
.
insert
(
1
,
(
topk_name
,
AverageMeter
(
topk_name
,
'.5f'
,
postfix
=
","
)))
metric_list
.
insert
(
1
,
(
"top1"
,
AverageMeter
(
"top1"
,
'.5f'
,
postfix
=
","
)))
metric_list
=
OrderedDict
(
metric_list
)
...
...
@@ -316,35 +305,43 @@ def run(dataloader,
for
name
,
fetch
in
fetchs
.
items
():
metric_list
[
name
].
update
(
fetch
.
numpy
()[
0
],
batch_size
)
metric_list
[
'batch_time'
].
update
(
time
.
time
()
-
tic
)
metric_list
[
"batch_time"
].
update
(
time
.
time
()
-
tic
)
tic
=
time
.
time
()
fetchs_str
=
' '
.
join
([
str
(
m
.
value
)
for
m
in
metric_list
.
values
()])
if
idx
%
print_interval
==
0
:
ips_info
=
"ips: {:.5f} images/sec."
.
format
(
batch_size
/
metric_list
[
"batch_time"
].
val
)
if
mode
==
'eval'
:
logger
.
info
(
"{:s} step:{:<4d}
{:s}s"
.
format
(
mode
,
idx
,
fetchs_str
))
logger
.
info
(
"{:s} step:{:<4d}
, {:s} {:s}"
.
format
(
mode
,
idx
,
fetchs_str
,
ips_info
))
else
:
epoch_str
=
"epoch:{:<3d}"
.
format
(
epoch
)
step_str
=
"{:s} step:{:<4d}"
.
format
(
mode
,
idx
)
logger
.
info
(
"{:s}
{:s} {:s}s
"
.
format
(
logger
.
info
(
"{:s}
, {:s}, {:s} {:s}
"
.
format
(
logger
.
coloring
(
epoch_str
,
"HEADER"
)
if
idx
==
0
else
epoch_str
,
logger
.
coloring
(
step_str
,
"PURPLE"
),
logger
.
coloring
(
fetchs_str
,
'OKGREEN'
)))
logger
.
coloring
(
fetchs_str
,
'OKGREEN'
),
logger
.
coloring
(
ips_info
,
'OKGREEN'
)))
end_str
=
' '
.
join
([
str
(
m
.
mean
)
for
m
in
metric_list
.
values
()]
+
[
metric_list
[
'batch_time'
].
total
])
ips_info
=
"ips: {:.5f} images/sec."
.
format
(
batch_size
*
metric_list
[
"batch_time"
].
count
/
metric_list
[
"batch_time"
].
sum
)
if
mode
==
'eval'
:
logger
.
info
(
"END {:s} {:s}
s"
.
format
(
mode
,
end_str
))
logger
.
info
(
"END {:s} {:s}
{:s}"
.
format
(
mode
,
end_str
,
ips_info
))
else
:
end_epoch_str
=
"END epoch:{:<3d}"
.
format
(
epoch
)
logger
.
info
(
"{:s} {:s} {:s}
s
"
.
format
(
logger
.
info
(
"{:s} {:s} {:s}
{:s}
"
.
format
(
logger
.
coloring
(
end_epoch_str
,
"RED"
),
logger
.
coloring
(
mode
,
"PURPLE"
),
logger
.
coloring
(
end_str
,
"OKGREEN"
)))
logger
.
coloring
(
end_str
,
"OKGREEN"
),
logger
.
coloring
(
ips_info
,
"OKGREEN"
),
))
# return top1_acc in order to save the best model
if
mode
==
'valid'
:
...
...
tools/train.py
浏览文件 @
ee102078
...
...
@@ -60,7 +60,8 @@ def main(args):
place
=
'gpu:{}'
.
format
(
ParallelEnv
().
dev_id
)
if
use_gpu
else
'cpu'
place
=
paddle
.
set_device
(
place
)
use_data_parallel
=
int
(
os
.
getenv
(
"PADDLE_TRAINERS_NUM"
,
1
))
!=
1
trainer_num
=
int
(
os
.
getenv
(
"PADDLE_TRAINERS_NUM"
,
1
))
use_data_parallel
=
trainer_num
!=
1
config
[
"use_data_parallel"
]
=
use_data_parallel
if
config
[
"use_data_parallel"
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录