Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
df3e75dd
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看板
提交
df3e75dd
编写于
5月 18, 2022
作者:
G
gaotingquan
提交者:
Tingquan Gao
6月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: warn when topk parameter setting is wrong
上级
4003cdb7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
27 deletion
+29
-27
ppcls/engine/engine.py
ppcls/engine/engine.py
+20
-25
ppcls/engine/evaluation/classification.py
ppcls/engine/evaluation/classification.py
+0
-1
ppcls/metric/metrics.py
ppcls/metric/metrics.py
+9
-1
未找到文件。
ppcls/engine/engine.py
浏览文件 @
df3e75dd
...
@@ -152,39 +152,34 @@ class Engine(object):
...
@@ -152,39 +152,34 @@ class Engine(object):
self
.
eval_loss_func
=
None
self
.
eval_loss_func
=
None
# build metric
# build metric
if
self
.
mode
==
'train'
:
if
self
.
mode
==
'train'
and
"Metric"
in
self
.
config
and
"Train"
in
self
.
config
[
metric_config
=
self
.
config
.
get
(
"Metric"
)
"Metric"
]:
if
metric_config
is
not
None
:
metric_config
=
self
.
config
[
"Metric"
][
"Train"
]
metric_config
=
metric_config
.
get
(
"Train"
)
if
hasattr
(
self
.
train_dataloader
,
"collate_fn"
if
metric_config
is
not
None
:
)
and
self
.
train_dataloader
.
collate_fn
is
not
None
:
if
hasattr
(
for
m_idx
,
m
in
enumerate
(
metric_config
):
self
.
train_dataloader
,
"collate_fn"
if
"TopkAcc"
in
m
:
)
and
self
.
train_dataloader
.
collate_fn
is
not
None
:
msg
=
f
"'TopkAcc' metric can not be used when setting 'batch_transform_ops' in config. The 'TopkAcc' metric has been removed."
for
m_idx
,
m
in
enumerate
(
metric_config
):
logger
.
warning
(
msg
)
if
"TopkAcc"
in
m
:
break
msg
=
f
"'TopkAcc' metric can not be used when setting 'batch_transform_ops' in config. The 'TopkAcc' metric has been removed."
metric_config
.
pop
(
m_idx
)
logger
.
warning
(
msg
)
self
.
train_metric_func
=
build_metrics
(
metric_config
)
break
metric_config
.
pop
(
m_idx
)
self
.
train_metric_func
=
build_metrics
(
metric_config
)
else
:
self
.
train_metric_func
=
None
else
:
else
:
self
.
train_metric_func
=
None
self
.
train_metric_func
=
None
if
self
.
mode
==
"eval"
or
(
self
.
mode
==
"train"
and
if
self
.
mode
==
"eval"
or
(
self
.
mode
==
"train"
and
self
.
config
[
"Global"
][
"eval_during_train"
]):
self
.
config
[
"Global"
][
"eval_during_train"
]):
metric_config
=
self
.
config
.
get
(
"Metric"
)
if
self
.
eval_mode
==
"classification"
:
if
self
.
eval_mode
==
"classification"
:
if
metric_config
is
not
None
:
if
"Metric"
in
self
.
config
and
"Eval"
in
self
.
config
[
"Metric"
]:
metric_config
=
metric_config
.
get
(
"Eval"
)
self
.
eval_metric_func
=
build_metrics
(
self
.
config
[
"Metric"
]
if
metric_config
is
not
None
:
[
"Eval"
])
self
.
eval_metric_func
=
build_metrics
(
metric_config
)
else
:
self
.
eval_metric_func
=
None
elif
self
.
eval_mode
==
"retrieval"
:
elif
self
.
eval_mode
==
"retrieval"
:
if
metric_config
is
None
:
if
"Metric"
in
self
.
config
and
"Eval"
in
self
.
config
[
"Metric"
]
:
metric_config
=
[{
"name"
:
"Recallk"
,
"topk"
:
(
1
,
5
)}
]
metric_config
=
metric_config
[
"Metric"
][
"Eval"
]
else
:
else
:
metric_config
=
metric_config
[
"Eval"
]
metric_config
=
[{
"name"
:
"Recallk"
,
"topk"
:
(
1
,
5
)}
]
self
.
eval_metric_func
=
build_metrics
(
metric_config
)
self
.
eval_metric_func
=
build_metrics
(
metric_config
)
else
:
else
:
self
.
eval_metric_func
=
None
self
.
eval_metric_func
=
None
...
...
ppcls/engine/evaluation/classification.py
浏览文件 @
df3e75dd
...
@@ -34,7 +34,6 @@ def classification_eval(engine, epoch_id=0):
...
@@ -34,7 +34,6 @@ def classification_eval(engine, epoch_id=0):
}
}
print_batch_step
=
engine
.
config
[
"Global"
][
"print_batch_step"
]
print_batch_step
=
engine
.
config
[
"Global"
][
"print_batch_step"
]
metric_key
=
None
tic
=
time
.
time
()
tic
=
time
.
time
()
accum_samples
=
0
accum_samples
=
0
total_samples
=
len
(
total_samples
=
len
(
...
...
ppcls/metric/metrics.py
浏览文件 @
df3e75dd
...
@@ -26,6 +26,7 @@ from easydict import EasyDict
...
@@ -26,6 +26,7 @@ from easydict import EasyDict
from
ppcls.metric.avg_metrics
import
AvgMetrics
from
ppcls.metric.avg_metrics
import
AvgMetrics
from
ppcls.utils.misc
import
AverageMeter
,
AttrMeter
from
ppcls.utils.misc
import
AverageMeter
,
AttrMeter
from
ppcls.utils
import
logger
class
TopkAcc
(
AvgMetrics
):
class
TopkAcc
(
AvgMetrics
):
...
@@ -47,8 +48,15 @@ class TopkAcc(AvgMetrics):
...
@@ -47,8 +48,15 @@ class TopkAcc(AvgMetrics):
if
isinstance
(
x
,
dict
):
if
isinstance
(
x
,
dict
):
x
=
x
[
"logits"
]
x
=
x
[
"logits"
]
output_dims
=
x
.
shape
[
-
1
]
metric_dict
=
dict
()
metric_dict
=
dict
()
for
k
in
self
.
topk
:
for
idx
,
k
in
enumerate
(
self
.
topk
):
if
output_dims
<
k
:
msg
=
f
"The output dims(
{
output_dims
}
) is less than k(
{
k
}
), and the argument
{
k
}
of Topk has been removed."
logger
.
warning
(
msg
)
self
.
topk
.
pop
(
idx
)
continue
metric_dict
[
"top{}"
.
format
(
k
)]
=
paddle
.
metric
.
accuracy
(
metric_dict
[
"top{}"
.
format
(
k
)]
=
paddle
.
metric
.
accuracy
(
x
,
label
,
k
=
k
)
x
,
label
,
k
=
k
)
self
.
avg_meters
[
"top{}"
.
format
(
k
)].
update
(
metric_dict
[
"top{}"
.
format
(
k
)],
x
.
shape
[
0
])
self
.
avg_meters
[
"top{}"
.
format
(
k
)].
update
(
metric_dict
[
"top{}"
.
format
(
k
)],
x
.
shape
[
0
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录