Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
62772c11
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看板
提交
62772c11
编写于
5月 29, 2020
作者:
S
shippingwang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add visualdl
上级
bd67368c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
29 deletion
+51
-29
ppcls/utils/logger.py
ppcls/utils/logger.py
+31
-23
tools/program.py
tools/program.py
+8
-1
tools/train.py
tools/train.py
+12
-5
未找到文件。
ppcls/utils/logger.py
浏览文件 @
62772c11
...
...
@@ -19,9 +19,10 @@ import datetime
from
imp
import
reload
reload
(
logging
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
"%(asctime)s %(levelname)s: %(message)s"
,
datefmt
=
"%Y-%m-%d %H:%M:%S"
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
"%(asctime)s %(levelname)s: %(message)s"
,
datefmt
=
"%Y-%m-%d %H:%M:%S"
)
def
time_zone
(
sec
,
fmt
):
...
...
@@ -32,22 +33,22 @@ def time_zone(sec, fmt):
logging
.
Formatter
.
converter
=
time_zone
_logger
=
logging
.
getLogger
(
__name__
)
Color
=
{
'RED'
:
'
\033
[31m'
,
'HEADER'
:
'
\033
[35m'
,
# deep
purple
'PURPLE'
:
'
\033
[95m'
,
# purple
'OKBLUE'
:
'
\033
[94m'
,
'OKGREEN'
:
'
\033
[92m'
,
'WARNING'
:
'
\033
[93m'
,
'FAIL'
:
'
\033
[91m'
,
'ENDC'
:
'
\033
[0m'
}
Color
=
{
'RED'
:
'
\033
[31m'
,
'HEADER'
:
'
\033
[35m'
,
# deep purple
'PURPLE'
:
'
\033
[95m'
,
#
purple
'OKBLUE'
:
'
\033
[94m'
,
'OKGREEN'
:
'
\033
[92m'
,
'WARNING'
:
'
\033
[93m'
,
'FAIL'
:
'
\033
[91m'
,
'ENDC'
:
'
\033
[0m'
}
def
coloring
(
message
,
color
=
"OKGREEN"
):
assert
color
in
Color
.
keys
()
if
os
.
environ
.
get
(
'PADDLECLAS_COLORING'
,
False
):
return
Color
[
color
]
+
str
(
message
)
+
Color
[
"ENDC"
]
return
Color
[
color
]
+
str
(
message
)
+
Color
[
"ENDC"
]
else
:
return
message
...
...
@@ -80,6 +81,12 @@ def error(fmt, *args):
_logger
.
error
(
coloring
(
fmt
,
"FAIL"
),
*
args
)
def
scaler
(
name
,
value
,
step
,
path
):
from
visualdl
import
LogWriter
vdl_writer
=
LogWriter
(
path
)
vdl_writer
.
add_scalar
(
name
,
value
,
step
)
def
advertise
():
"""
Show the advertising message like the following:
...
...
@@ -99,12 +106,13 @@ def advertise():
website
=
"https://github.com/PaddlePaddle/PaddleClas"
AD_LEN
=
6
+
len
(
max
([
copyright
,
ad
,
website
],
key
=
len
))
info
(
coloring
(
"
\n
{0}
\n
{1}
\n
{2}
\n
{3}
\n
{4}
\n
{5}
\n
{6}
\n
{7}
\n
"
.
format
(
"="
*
(
AD_LEN
+
4
),
"=={}=="
.
format
(
copyright
.
center
(
AD_LEN
)),
"="
*
(
AD_LEN
+
4
),
"=={}=="
.
format
(
' '
*
AD_LEN
),
"=={}=="
.
format
(
ad
.
center
(
AD_LEN
)),
"=={}=="
.
format
(
' '
*
AD_LEN
),
"=={}=="
.
format
(
website
.
center
(
AD_LEN
)),
"="
*
(
AD_LEN
+
4
),
),
"RED"
))
info
(
coloring
(
"
\n
{0}
\n
{1}
\n
{2}
\n
{3}
\n
{4}
\n
{5}
\n
{6}
\n
{7}
\n
"
.
format
(
"="
*
(
AD_LEN
+
4
),
"=={}=="
.
format
(
copyright
.
center
(
AD_LEN
)),
"="
*
(
AD_LEN
+
4
),
"=={}=="
.
format
(
' '
*
AD_LEN
),
"=={}=="
.
format
(
ad
.
center
(
AD_LEN
)),
"=={}=="
.
format
(
' '
*
AD_LEN
),
"=={}=="
.
format
(
website
.
center
(
AD_LEN
)),
"="
*
(
AD_LEN
+
4
),
),
"RED"
))
tools/program.py
浏览文件 @
62772c11
...
...
@@ -384,7 +384,10 @@ def compile(config, program, loss_name=None):
return
compiled_program
def
run
(
dataloader
,
exe
,
program
,
fetchs
,
epoch
=
0
,
mode
=
'train'
):
total_step
=
0
def
run
(
dataloader
,
exe
,
program
,
fetchs
,
epoch
=
0
,
mode
=
'train'
,
vdl_dir
=
None
):
"""
Feed data to the model and fetch the measures and loss
...
...
@@ -412,6 +415,10 @@ def run(dataloader, exe, program, fetchs, epoch=0, mode='train'):
metric_list
[
i
].
update
(
m
[
0
],
len
(
batch
[
0
]))
fetchs_str
=
''
.
join
([
str
(
m
.
value
)
+
' '
for
m
in
metric_list
]
+
[
batch_time
.
value
])
+
's'
if
vdl_dir
:
global
total_step
logger
.
scaler
(
'loss'
,
metrics
[
0
][
0
],
total_step
,
vdl_dir
)
total_step
+=
1
if
mode
==
'eval'
:
logger
.
info
(
"{:s} step:{:<4d} {:s}s"
.
format
(
mode
,
idx
,
fetchs_str
))
else
:
...
...
tools/train.py
浏览文件 @
62772c11
...
...
@@ -38,6 +38,11 @@ def parse_args():
type
=
str
,
default
=
'configs/ResNet/ResNet50.yaml'
,
help
=
'config file path'
)
parser
.
add_argument
(
'--vdl_dir'
,
type
=
str
,
default
=
"scaler"
,
help
=
'VisualDL logging directory for image.'
)
parser
.
add_argument
(
'-o'
,
'--override'
,
...
...
@@ -94,7 +99,7 @@ def main(args):
for
epoch_id
in
range
(
config
.
epochs
):
# 1. train with train dataset
program
.
run
(
train_dataloader
,
exe
,
compiled_train_prog
,
train_fetchs
,
epoch_id
,
'train'
)
epoch_id
,
'train'
,
args
.
vdl_dir
)
if
int
(
os
.
getenv
(
"PADDLE_TRAINER_ID"
,
0
))
==
0
:
# 2. validate with validate dataset
if
config
.
validate
and
epoch_id
%
config
.
valid_interval
==
0
:
...
...
@@ -103,13 +108,15 @@ def main(args):
epoch_id
,
'valid'
)
if
top1_acc
>
best_top1_acc
:
best_top1_acc
=
top1_acc
message
=
"The best top1 acc {:.5f}, in epoch: {:d}"
.
format
(
best_top1_acc
,
epoch_id
)
message
=
"The best top1 acc {:.5f}, in epoch: {:d}"
.
format
(
best_top1_acc
,
epoch_id
)
logger
.
info
(
"{:s}"
.
format
(
logger
.
coloring
(
message
,
"RED"
)))
if
epoch_id
%
config
.
save_interval
==
0
:
if
epoch_id
%
config
.
save_interval
==
0
:
model_path
=
os
.
path
.
join
(
config
.
model_save_dir
,
config
.
ARCHITECTURE
[
"name"
])
save_model
(
train_prog
,
model_path
,
"best_model_in_epoch_"
+
str
(
epoch_id
))
config
.
ARCHITECTURE
[
"name"
])
save_model
(
train_prog
,
model_path
,
"best_model_in_epoch_"
+
str
(
epoch_id
))
# 3. save the persistable model
if
epoch_id
%
config
.
save_interval
==
0
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录