Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
47039c82
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看板
未验证
提交
47039c82
编写于
6月 08, 2021
作者:
F
Felix
提交者:
GitHub
6月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update trainer.py
上级
38201d26
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
28 deletion
+32
-28
ppcls/engine/trainer.py
ppcls/engine/trainer.py
+32
-28
未找到文件。
ppcls/engine/trainer.py
浏览文件 @
47039c82
...
...
@@ -404,37 +404,40 @@ class Trainer(object):
if
query_query_id
is
not
None
:
query_id_blocks
=
paddle
.
split
(
query_query_id
,
num_or_sections
=
sections
)
image_id_blocks
=
paddle
.
split
(
query_img_id
,
num_or_sections
=
sections
)
image_id_blocks
=
paddle
.
split
(
query_img_id
,
num_or_sections
=
sections
)
metric_key
=
None
for
block_idx
,
block_fea
in
enumerate
(
fea_blocks
):
similarity_matrix
=
paddle
.
matmul
(
block_fea
,
gallery_feas
,
transpose_y
=
True
)
if
query_query_id
is
not
None
:
query_id_block
=
query_id_blocks
[
block_idx
]
query_id_mask
=
(
query_id_block
!=
gallery_unique_id
.
t
())
image_id_block
=
image_id_blocks
[
block_idx
]
image_id_mask
=
(
image_id_block
!=
gallery_img_id
.
t
())
keep_mask
=
paddle
.
logical_or
(
query_id_mask
,
image_id_mask
)
similarity_matrix
=
similarity_matrix
*
keep_mask
.
astype
(
"float32"
)
if
cum_similarity_matrix
is
None
:
cum_similarity_matrix
=
similarity_matrix
else
:
cum_similarity_matrix
=
paddle
.
concat
(
[
cum_similarity_matrix
,
similarity_matrix
],
axis
=
0
)
# calc metric
if
self
.
eval_metric_func
is
not
None
:
metric_dict
=
self
.
eval_metric_func
(
cum_similarity_matrix
,
query_img_id
,
gallery_img_id
)
else
:
if
self
.
eval_metric_func
is
None
:
metric_dict
=
{
metric_key
:
0.
}
else
:
metric_dict
=
dict
()
for
block_idx
,
block_fea
in
enumerate
(
fea_blocks
):
similarity_matrix
=
paddle
.
matmul
(
block_fea
,
gallery_feas
,
transpose_y
=
True
)
if
query_query_id
is
not
None
:
query_id_block
=
query_id_blocks
[
block_idx
]
query_id_mask
=
(
query_id_block
!=
gallery_unique_id
.
t
())
image_id_block
=
image_id_blocks
[
block_idx
]
image_id_mask
=
(
image_id_block
!=
gallery_img_id
.
t
())
keep_mask
=
paddle
.
logical_or
(
query_id_mask
,
image_id_mask
)
similarity_matrix
=
similarity_matrix
*
keep_mask
.
astype
(
"float32"
)
metric_tmp
=
self
.
eval_metric_func
(
similarity_matrix
,
image_id_blocks
[
block_idx
],
gallery_img_id
)
for
key
in
metric_tmp
:
if
key
not
in
metric_dict
:
metric_dict
[
key
]
=
metric_tmp
[
key
]
else
:
metric_dict
[
key
]
+=
metric_tmp
[
key
]
num_sections
=
len
(
fea_blocks
)
for
key
in
metric_dict
:
metric_dict
[
key
]
=
metric_dict
[
key
]
/
num_sections
metric_info_list
=
[]
for
key
in
metric_dict
:
if
metric_key
is
None
:
metric_key
=
key
...
...
@@ -442,7 +445,8 @@ class Trainer(object):
metric_msg
=
", "
.
join
(
metric_info_list
)
logger
.
info
(
"[Eval][Epoch {}][Avg]{}"
.
format
(
epoch_id
,
metric_msg
))
return
metric_dict
[
metric_key
]
return
metric_dict
[
metric_key
]
def
_cal_feature
(
self
,
name
=
'gallery'
):
all_feas
=
None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录