Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
463980f3
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
1 年多 前同步成功
通知
116
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看板
未验证
提交
463980f3
编写于
11月 20, 2020
作者:
L
littletomatodonkey
提交者:
GitHub
11月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add support for multi cards eval (#413)
* add support for multi cards eva
上级
6be63583
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
61 addition
and
51 deletion
+61
-51
ppcls/data/reader.py
ppcls/data/reader.py
+13
-23
ppcls/modeling/architectures/resnet_vd.py
ppcls/modeling/architectures/resnet_vd.py
+1
-1
ppcls/utils/save_load.py
ppcls/utils/save_load.py
+2
-0
tools/program.py
tools/program.py
+23
-4
tools/train.py
tools/train.py
+22
-23
未找到文件。
ppcls/data/reader.py
浏览文件 @
463980f3
...
...
@@ -242,29 +242,19 @@ class Reader:
dataset
=
CommonDataset
(
self
.
params
)
if
self
.
params
[
'mode'
]
==
"train"
:
batch_sampler
=
DistributedBatchSampler
(
dataset
,
batch_size
=
batch_size
,
shuffle
=
self
.
shuffle
,
drop_last
=
True
)
loader
=
DataLoader
(
dataset
,
batch_sampler
=
batch_sampler
,
collate_fn
=
self
.
collate_fn
,
places
=
self
.
places
,
return_list
=
True
,
num_workers
=
self
.
params
[
"num_workers"
])
else
:
loader
=
DataLoader
(
dataset
,
places
=
self
.
places
,
batch_size
=
batch_size
,
drop_last
=
False
,
return_list
=
True
,
shuffle
=
False
,
num_workers
=
self
.
params
[
"num_workers"
])
is_train
=
self
.
params
[
'mode'
]
==
"train"
batch_sampler
=
DistributedBatchSampler
(
dataset
,
batch_size
=
batch_size
,
shuffle
=
self
.
shuffle
and
is_train
,
drop_last
=
is_train
)
loader
=
DataLoader
(
dataset
,
batch_sampler
=
batch_sampler
,
collate_fn
=
self
.
collate_fn
if
is_train
else
None
,
places
=
self
.
places
,
return_list
=
True
,
num_workers
=
self
.
params
[
"num_workers"
])
return
loader
...
...
ppcls/modeling/architectures/resnet_vd.py
浏览文件 @
463980f3
...
...
@@ -253,7 +253,7 @@ class ResNet_vd(nn.Layer):
for
block
in
range
(
len
(
depth
)):
shortcut
=
False
for
i
in
range
(
depth
[
block
]):
if
layers
in
[
101
,
152
]
and
block
==
2
:
if
layers
in
[
101
,
152
,
200
]
and
block
==
2
:
if
i
==
0
:
conv_name
=
"res"
+
str
(
block
+
2
)
+
"a"
else
:
...
...
ppcls/utils/save_load.py
浏览文件 @
463980f3
...
...
@@ -143,6 +143,8 @@ def save_model(net, optimizer, model_path, epoch_id, prefix='ppcls'):
"""
save model to the target path
"""
if
paddle
.
distributed
.
get_rank
()
!=
0
:
return
model_path
=
os
.
path
.
join
(
model_path
,
str
(
epoch_id
))
_mkdir_if_not_exist
(
model_path
)
model_prefix
=
os
.
path
.
join
(
model_path
,
prefix
)
...
...
tools/program.py
浏览文件 @
463980f3
...
...
@@ -108,7 +108,8 @@ def create_metric(out,
architecture
,
topk
=
5
,
classes_num
=
1000
,
use_distillation
=
False
):
use_distillation
=
False
,
mode
=
"train"
):
"""
Create measures of model accuracy, such as top1 and top5
...
...
@@ -117,6 +118,8 @@ def create_metric(out,
feeds(dict): dict of model input variables(included label)
topk(int): usually top5
classes_num(int): num of classes
use_distillation(bool): whether to use distillation training
mode(str): mode, train/valid
Returns:
fetchs(dict): dict of measures
...
...
@@ -133,10 +136,20 @@ def create_metric(out,
fetchs
=
OrderedDict
()
# set top1 to fetchs
top1
=
paddle
.
metric
.
accuracy
(
softmax_out
,
label
=
label
,
k
=
1
)
fetchs
[
'top1'
]
=
top1
# set topk to fetchs
k
=
min
(
topk
,
classes_num
)
topk
=
paddle
.
metric
.
accuracy
(
softmax_out
,
label
=
label
,
k
=
k
)
# multi cards' eval
if
mode
!=
"train"
and
paddle
.
distributed
.
get_world_size
()
>
1
:
top1
=
paddle
.
distributed
.
all_reduce
(
top1
,
op
=
paddle
.
distributed
.
ReduceOp
.
SUM
)
/
paddle
.
distributed
.
get_world_size
()
topk
=
paddle
.
distributed
.
all_reduce
(
topk
,
op
=
paddle
.
distributed
.
ReduceOp
.
SUM
)
/
paddle
.
distributed
.
get_world_size
()
fetchs
[
'top1'
]
=
top1
topk_name
=
'top{}'
.
format
(
k
)
fetchs
[
topk_name
]
=
topk
...
...
@@ -175,8 +188,14 @@ def create_fetchs(feeds, net, config, mode="train"):
fetchs
[
'loss'
]
=
create_loss
(
feeds
,
out
,
architecture
,
classes_num
,
epsilon
,
use_mix
,
use_distillation
)
if
not
use_mix
:
metric
=
create_metric
(
out
,
feeds
[
"label"
],
architecture
,
topk
,
classes_num
,
use_distillation
)
metric
=
create_metric
(
out
,
feeds
[
"label"
],
architecture
,
topk
,
classes_num
,
use_distillation
,
mode
=
mode
)
fetchs
.
update
(
metric
)
return
fetchs
...
...
tools/train.py
浏览文件 @
463980f3
...
...
@@ -77,7 +77,7 @@ def main(args):
train_dataloader
=
Reader
(
config
,
'train'
,
places
=
place
)()
if
config
.
validate
and
paddle
.
distributed
.
get_rank
()
==
0
:
if
config
.
validate
:
valid_dataloader
=
Reader
(
config
,
'valid'
,
places
=
place
)()
last_epoch_id
=
config
.
get
(
"last_epoch"
,
-
1
)
...
...
@@ -89,28 +89,27 @@ def main(args):
program
.
run
(
train_dataloader
,
config
,
net
,
optimizer
,
lr_scheduler
,
epoch_id
,
'train'
)
if
paddle
.
distributed
.
get_rank
()
==
0
:
# 2. validate with validate dataset
if
config
.
validate
and
epoch_id
%
config
.
valid_interval
==
0
:
net
.
eval
()
top1_acc
=
program
.
run
(
valid_dataloader
,
config
,
net
,
None
,
None
,
epoch_id
,
'valid'
)
if
top1_acc
>
best_top1_acc
:
best_top1_acc
=
top1_acc
best_top1_epoch
=
epoch_id
if
epoch_id
%
config
.
save_interval
==
0
:
model_path
=
os
.
path
.
join
(
config
.
model_save_dir
,
config
.
ARCHITECTURE
[
"name"
])
save_model
(
net
,
optimizer
,
model_path
,
"best_model"
)
message
=
"The best top1 acc {:.5f}, in epoch: {:d}"
.
format
(
best_top1_acc
,
best_top1_epoch
)
logger
.
info
(
"{:s}"
.
format
(
logger
.
coloring
(
message
,
"RED"
)))
# 3. save the persistable model
if
epoch_id
%
config
.
save_interval
==
0
:
model_path
=
os
.
path
.
join
(
config
.
model_save_dir
,
config
.
ARCHITECTURE
[
"name"
])
save_model
(
net
,
optimizer
,
model_path
,
epoch_id
)
# 2. validate with validate dataset
if
config
.
validate
and
epoch_id
%
config
.
valid_interval
==
0
:
net
.
eval
()
top1_acc
=
program
.
run
(
valid_dataloader
,
config
,
net
,
None
,
None
,
epoch_id
,
'valid'
)
if
top1_acc
>
best_top1_acc
:
best_top1_acc
=
top1_acc
best_top1_epoch
=
epoch_id
if
epoch_id
%
config
.
save_interval
==
0
:
model_path
=
os
.
path
.
join
(
config
.
model_save_dir
,
config
.
ARCHITECTURE
[
"name"
])
save_model
(
net
,
optimizer
,
model_path
,
"best_model"
)
message
=
"The best top1 acc {:.5f}, in epoch: {:d}"
.
format
(
best_top1_acc
,
best_top1_epoch
)
logger
.
info
(
"{:s}"
.
format
(
logger
.
coloring
(
message
,
"RED"
)))
# 3. save the persistable model
if
epoch_id
%
config
.
save_interval
==
0
:
model_path
=
os
.
path
.
join
(
config
.
model_save_dir
,
config
.
ARCHITECTURE
[
"name"
])
save_model
(
net
,
optimizer
,
model_path
,
epoch_id
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录