Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
017b7b3a
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看板
提交
017b7b3a
编写于
6月 05, 2021
作者:
W
Wei Shengyu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'PaddlePaddle:develop_reg' into develop_reg
上级
934de965
ae24d832
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
57 deletion
+44
-57
ppcls/configs/Vehicle/ResNet50.yaml
ppcls/configs/Vehicle/ResNet50.yaml
+4
-4
ppcls/configs/Vehicle/ResNet50_ReID.yaml
ppcls/configs/Vehicle/ResNet50_ReID.yaml
+16
-13
ppcls/metric/metrics.py
ppcls/metric/metrics.py
+24
-40
未找到文件。
ppcls/configs/Vehicle/ResNet50.yaml
浏览文件 @
017b7b3a
...
@@ -148,9 +148,9 @@ Infer:
...
@@ -148,9 +148,9 @@ Infer:
Metric
:
Metric
:
Train
:
Train
:
-
Topk
:
-
Topk
Acc
:
k
:
[
1
,
5
]
top
k
:
[
1
,
5
]
Eval
:
Eval
:
-
Topk
:
-
Topk
Acc
:
k
:
[
1
,
5
]
top
k
:
[
1
,
5
]
ppcls/configs/Vehicle/ResNet50_ReID.yaml
浏览文件 @
017b7b3a
# global configs
# global configs
Trainer
:
name
:
TrainerReID
Global
:
Global
:
checkpoints
:
null
checkpoints
:
null
pretrained_model
:
null
pretrained_model
:
null
...
@@ -16,8 +14,7 @@ Global:
...
@@ -16,8 +14,7 @@ Global:
# used for static mode and model export
# used for static mode and model export
image_shape
:
[
3
,
224
,
224
]
image_shape
:
[
3
,
224
,
224
]
save_inference_dir
:
"
./inference"
save_inference_dir
:
"
./inference"
num_split
:
1
eval_mode
:
"
retrieval"
feature_normalize
:
True
# model architecture
# model architecture
Arch
:
Arch
:
...
@@ -99,10 +96,10 @@ DataLoader:
...
@@ -99,10 +96,10 @@ DataLoader:
loader
:
loader
:
num_workers
:
6
num_workers
:
6
use_shared_memory
:
False
use_shared_memory
:
False
Eval
:
Query
:
Query
:
# TOTO: modify to the latest trainer
# TOTO: modify to the latest trainer
dataset
:
dataset
:
name
:
"
VeriWild"
name
:
"
VeriWild"
image_root
:
"
/work/dataset/VeRI-Wild/images"
image_root
:
"
/work/dataset/VeRI-Wild/images"
cls_label_path
:
"
/work/dataset/VeRI-Wild/train_test_split/test_3000_id_query.txt"
cls_label_path
:
"
/work/dataset/VeRI-Wild/train_test_split/test_3000_id_query.txt"
...
@@ -114,18 +111,18 @@ DataLoader:
...
@@ -114,18 +111,18 @@ DataLoader:
mean
:
[
0.485
,
0.456
,
0.406
]
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
order
:
'
'
sampler
:
sampler
:
name
:
DistributedBatchSampler
name
:
DistributedBatchSampler
batch_size
:
64
batch_size
:
64
drop_last
:
False
drop_last
:
False
shuffle
:
False
shuffle
:
False
loader
:
loader
:
num_workers
:
6
num_workers
:
6
use_shared_memory
:
False
use_shared_memory
:
False
Gallery
:
Gallery
:
# TOTO: modify to the latest trainer
# TOTO: modify to the latest trainer
dataset
:
dataset
:
name
:
"
VeriWild"
name
:
"
VeriWild"
image_root
:
"
/work/dataset/VeRI-Wild/images"
image_root
:
"
/work/dataset/VeRI-Wild/images"
cls_label_path
:
"
/work/dataset/VeRI-Wild/train_test_split/test_3000_id.txt"
cls_label_path
:
"
/work/dataset/VeRI-Wild/train_test_split/test_3000_id.txt"
...
@@ -137,15 +134,21 @@ DataLoader:
...
@@ -137,15 +134,21 @@ DataLoader:
mean
:
[
0.485
,
0.456
,
0.406
]
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
order
:
'
'
sampler
:
sampler
:
name
:
DistributedBatchSampler
name
:
DistributedBatchSampler
batch_size
:
64
batch_size
:
64
drop_last
:
False
drop_last
:
False
shuffle
:
False
shuffle
:
False
loader
:
loader
:
num_workers
:
6
num_workers
:
6
use_shared_memory
:
False
use_shared_memory
:
False
Metric
:
Eval
:
-
Recallk
:
topk
:
[
1
,
5
]
-
mAP
:
{}
Infer
:
Infer
:
infer_imgs
:
"
docs/images/whl/demo.jpg"
infer_imgs
:
"
docs/images/whl/demo.jpg"
batch_size
:
10
batch_size
:
10
...
...
ppcls/metric/metrics.py
浏览文件 @
017b7b3a
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
numpy
as
np
import
numpy
as
np
import
paddle
import
paddle
import
paddle.nn
as
nn
import
paddle.nn
as
nn
from
functools
import
lru_cache
# TODO: fix the format
# TODO: fix the format
...
@@ -38,23 +39,13 @@ class TopkAcc(nn.Layer):
...
@@ -38,23 +39,13 @@ class TopkAcc(nn.Layer):
class
mAP
(
nn
.
Layer
):
class
mAP
(
nn
.
Layer
):
def
__init__
(
self
,
max_rank
=
50
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
self
.
max_rank
=
max_rank
def
forward
(
self
,
similarities_matrix
,
query_img_id
,
gallery_img_id
):
def
forward
(
self
,
similarities_matrix
,
query_img_id
,
gallery_img_id
):
metric_dict
=
dict
()
metric_dict
=
dict
()
num_q
,
num_g
=
similarities_matrix
.
shape
_
,
all_AP
,
_
=
get_metrics
(
similarities_matrix
,
query_img_id
,
q_pids
=
query_img_id
.
numpy
().
reshape
((
query_img_id
.
shape
[
0
]))
gallery_img_id
)
g_pids
=
gallery_img_id
.
numpy
().
reshape
((
gallery_img_id
.
shape
[
0
]))
if
num_g
<
self
.
max_rank
:
self
.
max_rank
=
num_g
print
(
'Note: number of gallery samples is quite small, got {}'
.
format
(
num_g
))
indices
=
paddle
.
argsort
(
similarities_matrix
,
axis
=
1
,
descending
=
True
).
numpy
()
_
,
all_AP
,
_
=
get_metrics
(
indices
,
num_q
,
num_g
,
q_pids
,
g_pids
,
self
.
max_rank
)
mAP
=
np
.
mean
(
all_AP
)
mAP
=
np
.
mean
(
all_AP
)
metric_dict
[
"mAP"
]
=
mAP
metric_dict
[
"mAP"
]
=
mAP
...
@@ -62,23 +53,13 @@ class mAP(nn.Layer):
...
@@ -62,23 +53,13 @@ class mAP(nn.Layer):
class
mINP
(
nn
.
Layer
):
class
mINP
(
nn
.
Layer
):
def
__init__
(
self
,
max_rank
=
50
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
self
.
max_rank
=
max_rank
def
forward
(
self
,
similarities_matrix
,
query_img_id
,
gallery_img_id
):
def
forward
(
self
,
similarities_matrix
,
query_img_id
,
gallery_img_id
):
metric_dict
=
dict
()
metric_dict
=
dict
()
num_q
,
num_g
=
similarities_matrix
.
shape
_
,
_
,
all_INP
=
get_metrics
(
similarities_matrix
,
query_img_id
,
q_pids
=
query_img_id
.
numpy
().
reshape
((
query_img_id
.
shape
[
0
]))
gallery_img_id
)
g_pids
=
gallery_img_id
.
numpy
().
reshape
((
gallery_img_id
.
shape
[
0
]))
if
num_g
<
self
.
max_rank
:
max_rank
=
num_g
print
(
'Note: number of gallery samples is quite small, got {}'
.
format
(
num_g
))
indices
=
paddle
.
argsort
(
similarities_matrix
,
axis
=
1
,
descending
=
True
).
numpy
()
_
,
_
,
all_INP
=
get_metrics
(
indices
,
num_q
,
num_g
,
q_pids
,
g_pids
,
self
.
max_rank
)
mINP
=
np
.
mean
(
all_INP
)
mINP
=
np
.
mean
(
all_INP
)
metric_dict
[
"mINP"
]
=
mINP
metric_dict
[
"mINP"
]
=
mINP
...
@@ -86,34 +67,37 @@ class mINP(nn.Layer):
...
@@ -86,34 +67,37 @@ class mINP(nn.Layer):
class
Recallk
(
nn
.
Layer
):
class
Recallk
(
nn
.
Layer
):
def
__init__
(
self
,
max_rank
=
50
,
topk
=
(
1
,
5
)):
def
__init__
(
self
,
topk
=
(
1
,
5
)):
super
().
__init__
()
super
().
__init__
()
self
.
max_rank
=
max_rank
assert
isinstance
(
topk
,
(
int
,
list
))
assert
isinstance
(
topk
,
(
int
,
list
))
if
isinstance
(
topk
,
int
):
if
isinstance
(
topk
,
int
):
topk
=
[
topk
]
topk
=
[
topk
]
self
.
topk
=
topk
self
.
topk
=
topk
self
.
max_rank
=
max
(
self
.
topk
)
if
max
(
self
.
topk
)
>
50
else
50
def
forward
(
self
,
similarities_matrix
,
query_img_id
,
gallery_img_id
):
def
forward
(
self
,
similarities_matrix
,
query_img_id
,
gallery_img_id
):
metric_dict
=
dict
()
metric_dict
=
dict
()
num_q
,
num_g
=
similarities_matrix
.
shape
all_cmc
,
_
,
_
=
get_metrics
(
similarities_matrix
,
query_img_id
,
q_pids
=
query_img_id
.
numpy
().
reshape
((
query_img_id
.
shape
[
0
]))
gallery_img_id
,
self
.
max_rank
)
g_pids
=
gallery_img_id
.
numpy
().
reshape
((
gallery_img_id
.
shape
[
0
]))
if
num_g
<
self
.
max_rank
:
max_rank
=
num_g
print
(
'Note: number of gallery samples is quite small, got {}'
.
format
(
num_g
))
indices
=
paddle
.
argsort
(
similarities_matrix
,
axis
=
1
,
descending
=
True
).
numpy
()
all_cmc
,
_
,
_
=
get_metrics
(
indices
,
num_q
,
num_g
,
q_pids
,
g_pids
,
self
.
max_rank
)
for
k
in
self
.
topk
:
for
k
in
self
.
topk
:
metric_dict
[
"recall{}"
.
format
(
k
)]
=
all_cmc
[
k
-
1
]
metric_dict
[
"recall{}"
.
format
(
k
)]
=
all_cmc
[
k
-
1
]
return
metric_dict
return
metric_dict
def
get_metrics
(
indices
,
num_q
,
num_g
,
q_pids
,
g_pids
,
max_rank
=
50
):
@
lru_cache
()
def
get_metrics
(
similarities_matrix
,
query_img_id
,
gallery_img_id
,
max_rank
=
50
):
num_q
,
num_g
=
similarities_matrix
.
shape
q_pids
=
query_img_id
.
numpy
().
reshape
((
query_img_id
.
shape
[
0
]))
g_pids
=
gallery_img_id
.
numpy
().
reshape
((
gallery_img_id
.
shape
[
0
]))
if
num_g
<
max_rank
:
max_rank
=
num_g
print
(
'Note: number of gallery samples is quite small, got {}'
.
format
(
num_g
))
indices
=
paddle
.
argsort
(
similarities_matrix
,
axis
=
1
,
descending
=
True
).
numpy
()
all_cmc
=
[]
all_cmc
=
[]
all_AP
=
[]
all_AP
=
[]
all_INP
=
[]
all_INP
=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录