Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
1a1eb3a1
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看板
提交
1a1eb3a1
编写于
8月 27, 2021
作者:
D
dongshuilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issues when gallery == query dataset
上级
ec5e07da
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
15 deletion
+30
-15
ppcls/data/__init__.py
ppcls/data/__init__.py
+3
-2
ppcls/engine/engine.py
ppcls/engine/engine.py
+13
-6
ppcls/engine/evaluation/retrieval.py
ppcls/engine/evaluation/retrieval.py
+14
-7
未找到文件。
ppcls/data/__init__.py
浏览文件 @
1a1eb3a1
...
@@ -54,8 +54,9 @@ def create_operators(params):
...
@@ -54,8 +54,9 @@ def create_operators(params):
def
build_dataloader
(
config
,
mode
,
device
,
use_dali
=
False
,
seed
=
None
):
def
build_dataloader
(
config
,
mode
,
device
,
use_dali
=
False
,
seed
=
None
):
assert
mode
in
[
'Train'
,
'Eval'
,
'Test'
,
'Gallery'
,
'Query'
assert
mode
in
[
],
"Mode should be Train, Eval, Test, Gallery, Query"
'Train'
,
'Eval'
,
'Test'
,
'Gallery'
,
'Query'
],
"Dataset mode should be Train, Eval, Test, Gallery, Query"
# build dataset
# build dataset
if
use_dali
:
if
use_dali
:
from
ppcls.data.dataloader.dali
import
dali_dataloader
from
ppcls.data.dataloader.dali
import
dali_dataloader
...
...
ppcls/engine/engine.py
浏览文件 @
1a1eb3a1
...
@@ -106,12 +106,19 @@ class Engine(object):
...
@@ -106,12 +106,19 @@ class Engine(object):
self
.
config
[
"DataLoader"
],
"Eval"
,
self
.
device
,
self
.
config
[
"DataLoader"
],
"Eval"
,
self
.
device
,
self
.
use_dali
)
self
.
use_dali
)
elif
self
.
eval_mode
==
"retrieval"
:
elif
self
.
eval_mode
==
"retrieval"
:
self
.
gallery_dataloader
=
build_dataloader
(
self
.
gallery_query_dataloader
=
None
self
.
config
[
"DataLoader"
][
"Eval"
],
"Gallery"
,
self
.
device
,
if
len
(
self
.
config
[
"DataLoader"
][
"Eval"
].
keys
())
==
1
:
self
.
use_dali
)
key
=
list
(
self
.
config
[
"DataLoader"
][
"Eval"
].
keys
())[
0
]
self
.
query_dataloader
=
build_dataloader
(
self
.
gallery_query_dataloader
=
build_dataloader
(
self
.
config
[
"DataLoader"
][
"Eval"
],
"Query"
,
self
.
device
,
self
.
config
[
"DataLoader"
][
"Eval"
],
key
,
self
.
device
,
self
.
use_dali
)
self
.
use_dali
)
else
:
self
.
gallery_dataloader
=
build_dataloader
(
self
.
config
[
"DataLoader"
][
"Eval"
],
"Gallery"
,
self
.
device
,
self
.
use_dali
)
self
.
query_dataloader
=
build_dataloader
(
self
.
config
[
"DataLoader"
][
"Eval"
],
"Query"
,
self
.
device
,
self
.
use_dali
)
# build loss
# build loss
if
self
.
mode
==
"train"
:
if
self
.
mode
==
"train"
:
...
...
ppcls/engine/evaluation/retrieval.py
浏览文件 @
1a1eb3a1
...
@@ -23,10 +23,15 @@ from ppcls.utils import logger
...
@@ -23,10 +23,15 @@ from ppcls.utils import logger
def
retrieval_eval
(
evaler
,
epoch_id
=
0
):
def
retrieval_eval
(
evaler
,
epoch_id
=
0
):
evaler
.
model
.
eval
()
evaler
.
model
.
eval
()
# step1. build gallery
# step1. build gallery
gallery_feas
,
gallery_img_id
,
gallery_unique_id
=
cal_feature
(
if
evaler
.
gallery_query_dataloader
is
not
None
:
evaler
,
name
=
'gallery'
)
gallery_feas
,
gallery_img_id
,
gallery_unique_id
=
cal_feature
(
query_feas
,
query_img_id
,
query_query_id
=
cal_feature
(
evaler
,
name
=
'gallery_query'
)
evaler
,
name
=
'query'
)
query_feas
,
query_img_id
,
query_query_id
=
gallery_feas
,
gallery_img_id
,
gallery_unique_id
else
:
gallery_feas
,
gallery_img_id
,
gallery_unique_id
=
cal_feature
(
evaler
,
name
=
'gallery'
)
query_feas
,
query_img_id
,
query_query_id
=
cal_feature
(
evaler
,
name
=
'query'
)
# step2. do evaluation
# step2. do evaluation
sim_block_size
=
evaler
.
config
[
"Global"
].
get
(
"sim_block_size"
,
64
)
sim_block_size
=
evaler
.
config
[
"Global"
].
get
(
"sim_block_size"
,
64
)
...
@@ -93,6 +98,8 @@ def cal_feature(evaler, name='gallery'):
...
@@ -93,6 +98,8 @@ def cal_feature(evaler, name='gallery'):
dataloader
=
evaler
.
gallery_dataloader
dataloader
=
evaler
.
gallery_dataloader
elif
name
==
'query'
:
elif
name
==
'query'
:
dataloader
=
evaler
.
query_dataloader
dataloader
=
evaler
.
query_dataloader
elif
name
==
'gallery_query'
:
dataloader
=
evaler
.
gallery_query_dataloader
else
:
else
:
raise
RuntimeError
(
"Only support gallery or query dataset"
)
raise
RuntimeError
(
"Only support gallery or query dataset"
)
...
@@ -124,7 +131,7 @@ def cal_feature(evaler, name='gallery'):
...
@@ -124,7 +131,7 @@ def cal_feature(evaler, name='gallery'):
feas_norm
=
paddle
.
sqrt
(
feas_norm
=
paddle
.
sqrt
(
paddle
.
sum
(
paddle
.
square
(
batch_feas
),
axis
=
1
,
keepdim
=
True
))
paddle
.
sum
(
paddle
.
square
(
batch_feas
),
axis
=
1
,
keepdim
=
True
))
batch_feas
=
paddle
.
divide
(
batch_feas
,
feas_norm
)
batch_feas
=
paddle
.
divide
(
batch_feas
,
feas_norm
)
# do binarize
# do binarize
if
evaler
.
config
[
"Global"
].
get
(
"feature_binarize"
)
==
"round"
:
if
evaler
.
config
[
"Global"
].
get
(
"feature_binarize"
)
==
"round"
:
batch_feas
=
paddle
.
round
(
batch_feas
).
astype
(
"float32"
)
*
2.0
-
1.0
batch_feas
=
paddle
.
round
(
batch_feas
).
astype
(
"float32"
)
*
2.0
-
1.0
...
@@ -142,10 +149,10 @@ def cal_feature(evaler, name='gallery'):
...
@@ -142,10 +149,10 @@ def cal_feature(evaler, name='gallery'):
all_image_id
=
paddle
.
concat
([
all_image_id
,
batch
[
1
]])
all_image_id
=
paddle
.
concat
([
all_image_id
,
batch
[
1
]])
if
has_unique_id
:
if
has_unique_id
:
all_unique_id
=
paddle
.
concat
([
all_unique_id
,
batch
[
2
]])
all_unique_id
=
paddle
.
concat
([
all_unique_id
,
batch
[
2
]])
if
evaler
.
use_dali
:
if
evaler
.
use_dali
:
dataloader_tmp
.
reset
()
dataloader_tmp
.
reset
()
if
paddle
.
distributed
.
get_world_size
()
>
1
:
if
paddle
.
distributed
.
get_world_size
()
>
1
:
feat_list
=
[]
feat_list
=
[]
img_id_list
=
[]
img_id_list
=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录