Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
daf7eea2
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看板
提交
daf7eea2
编写于
4月 21, 2022
作者:
H
HydrogenSulfate
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code
上级
dfd77498
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
26 addition
and
30 deletion
+26
-30
ppcls/arch/utils.py
ppcls/arch/utils.py
+7
-7
ppcls/configs/PersonReID/ResNet50_strong_baseline_market1501.yaml
...nfigs/PersonReID/ResNet50_strong_baseline_market1501.yaml
+2
-2
ppcls/engine/engine.py
ppcls/engine/engine.py
+3
-3
ppcls/engine/evaluation/retrieval.py
ppcls/engine/evaluation/retrieval.py
+5
-12
ppcls/engine/train/train.py
ppcls/engine/train/train.py
+9
-6
未找到文件。
ppcls/arch/utils.py
浏览文件 @
daf7eea2
...
...
@@ -70,14 +70,14 @@ def get_param_attr_dict(ParamAttr_config: Union[None, bool, Dict[str, Dict]]
if
isinstance
(
ParamAttr_config
,
bool
):
return
ParamAttr_config
ParamAttr_dict
=
{}
if
'initi
lia
zer'
in
ParamAttr_config
:
initi
liazer_cfg
=
ParamAttr_config
.
get
(
'initilia
zer'
)
if
'name'
in
initi
lia
zer_cfg
:
initi
liazer_name
=
initilia
zer_cfg
.
pop
(
'name'
)
ParamAttr_dict
[
'initi
lia
zer'
]
=
getattr
(
paddle
.
nn
.
initializer
,
initi
liazer_name
)(
**
initilia
zer_cfg
)
if
'initi
ali
zer'
in
ParamAttr_config
:
initi
alizer_cfg
=
ParamAttr_config
.
get
(
'initiali
zer'
)
if
'name'
in
initi
ali
zer_cfg
:
initi
alizer_name
=
initiali
zer_cfg
.
pop
(
'name'
)
ParamAttr_dict
[
'initi
ali
zer'
]
=
getattr
(
paddle
.
nn
.
initializer
,
initi
alizer_name
)(
**
initiali
zer_cfg
)
else
:
raise
ValueError
(
f
"'name' must specified in initi
lia
zer_cfg"
)
raise
ValueError
(
f
"'name' must specified in initi
ali
zer_cfg"
)
if
'learning_rate'
in
ParamAttr_config
:
# NOTE: only support an single value now
learning_rate_value
=
ParamAttr_config
.
get
(
'learning_rate'
)
...
...
ppcls/configs/PersonReID/ResNet50_strong_baseline_market1501.yaml
浏览文件 @
daf7eea2
...
...
@@ -10,7 +10,7 @@ Global:
epochs
:
120
print_batch_step
:
20
use_visualdl
:
False
warmup_
epoch_
by_epoch
:
True
warmup_by_epoch
:
True
eval_mode
:
"
retrieval"
re_ranking
:
True
# used for static mode and model export
...
...
@@ -68,7 +68,7 @@ Optimizer:
values
:
[
0.00035
,
0.000035
,
0.0000035
]
warmup_epoch
:
10
warmup_start_lr
:
0.0000035
warmup_
epoch_
by_epoch
:
True
warmup_by_epoch
:
True
regularizer
:
name
:
'
L2'
coeff
:
0.0005
...
...
ppcls/engine/engine.py
浏览文件 @
daf7eea2
...
...
@@ -299,11 +299,11 @@ class Engine(object):
self
.
max_iter
=
len
(
self
.
train_dataloader
)
-
1
if
platform
.
system
(
)
==
"Windows"
else
len
(
self
.
train_dataloader
)
if
self
.
config
[
"Global"
].
get
(
"warmup_
epoch_
by_epoch"
,
False
):
if
self
.
config
[
"Global"
].
get
(
"warmup_by_epoch"
,
False
):
for
i
in
range
(
len
(
self
.
lr_sch
)):
self
.
lr_sch
[
i
].
step
()
logger
.
info
(
"lr_sch step once before first epoch, when Global.warmup_
epoch_
by_epoch=True"
"lr_sch step once before first epoch, when Global.warmup_by_epoch=True"
)
for
epoch_id
in
range
(
best_metric
[
"epoch"
]
+
1
,
...
...
@@ -312,7 +312,7 @@ class Engine(object):
# for one epoch train
self
.
train_epoch_func
(
self
,
epoch_id
,
print_batch_step
)
if
self
.
config
[
"Global"
].
get
(
"warmup_
epoch_
by_epoch"
,
False
):
if
self
.
config
[
"Global"
].
get
(
"warmup_by_epoch"
,
False
):
for
i
in
range
(
len
(
self
.
lr_sch
)):
self
.
lr_sch
[
i
].
step
()
...
...
ppcls/engine/evaluation/retrieval.py
浏览文件 @
daf7eea2
...
...
@@ -83,20 +83,16 @@ def retrieval_eval(engine, epoch_id=0):
0
]
/
len
(
query_feas
)
else
:
distmat
=
re_ranking
(
query_feas
,
gallery_feas
,
query_img_id
,
query_query_id
,
gallery_img_id
,
gallery_unique_id
,
k1
=
20
,
k2
=
6
,
lambda_value
=
0.3
)
query_feas
,
gallery_feas
,
k1
=
20
,
k2
=
6
,
lambda_value
=
0.3
)
cmc
,
mAP
=
eval_func
(
distmat
,
np
.
squeeze
(
query_img_id
.
numpy
()),
np
.
squeeze
(
gallery_img_id
.
numpy
()),
np
.
squeeze
(
query_query_id
.
numpy
()),
np
.
squeeze
(
gallery_unique_id
.
numpy
()))
metric_dict
[
"recall1(RK)"
]
=
cmc
[
0
]
metric_dict
[
"recall5(RK)"
]
=
cmc
[
4
]
metric_dict
[
"mAP(RK)"
]
=
mAP
for
key
in
metric_tmp
:
metric_dict
[
key
]
=
metric_tmp
[
key
]
*
block_fea
.
shape
[
0
]
/
len
(
query_feas
)
...
...
@@ -176,7 +172,6 @@ def re_ranking(queFea,
k_reciprocal_expansion_index
=
np
.
unique
(
k_reciprocal_expansion_index
)
weight
=
np
.
exp
(
-
original_dist
[
i
,
k_reciprocal_expansion_index
])
V
[
i
,
k_reciprocal_expansion_index
]
=
weight
/
np
.
sum
(
weight
)
all_num_cost
=
time
.
time
()
-
t
original_dist
=
original_dist
[:
query_num
,
]
if
k2
!=
1
:
V_qe
=
np
.
zeros_like
(
V
,
dtype
=
np
.
float16
)
...
...
@@ -190,7 +185,6 @@ def re_ranking(queFea,
invIndex
.
append
(
np
.
where
(
V
[:,
i
]
!=
0
)[
0
])
jaccard_dist
=
np
.
zeros_like
(
original_dist
,
dtype
=
np
.
float16
)
gallery_num_cost
=
time
.
time
()
-
t
for
i
in
range
(
query_num
):
temp_min
=
np
.
zeros
(
shape
=
[
1
,
gallery_num
],
dtype
=
np
.
float16
)
indNonZero
=
np
.
where
(
V
[
i
,
:]
!=
0
)[
0
]
...
...
@@ -206,7 +200,6 @@ def re_ranking(queFea,
del
V
del
jaccard_dist
final_dist
=
final_dist
[:
query_num
,
query_num
:]
query_num_cost
=
time
.
time
()
-
t
return
final_dist
...
...
ppcls/engine/train/train.py
浏览文件 @
daf7eea2
...
...
@@ -57,24 +57,27 @@ def train_epoch(engine, epoch_id, print_batch_step):
if
engine
.
amp
:
scaled
=
engine
.
scaler
.
scale
(
loss_dict
[
"loss"
])
scaled
.
backward
()
# set BNneck.bias grad to zero
engine
.
model
.
neck
.
feat_bn
.
bias
.
grad
.
set_value
(
paddle
.
zeros_like
(
engine
.
model
.
neck
.
feat_bn
.
bias
.
grad
))
for
i
in
range
(
len
(
engine
.
optimizer
)):
engine
.
scaler
.
minimize
(
engine
.
optimizer
[
i
],
scaled
)
else
:
loss_dict
[
"loss"
].
backward
()
# set BNneck.bias grad to zero
engine
.
model
.
neck
.
feat_bn
.
bias
.
grad
.
set_value
(
paddle
.
zeros_like
(
engine
.
model
.
neck
.
feat_bn
.
bias
.
grad
))
for
i
in
range
(
len
(
engine
.
optimizer
)):
engine
.
optimizer
[
i
].
step
()
if
hasattr
(
engine
.
model
.
neck
,
'bn'
):
engine
.
model
.
neck
.
bn
.
bias
.
grad
.
set_value
(
paddle
.
zeros_like
(
engine
.
model
.
neck
.
bn
.
bias
.
grad
))
# clear grad
for
i
in
range
(
len
(
engine
.
optimizer
)):
engine
.
optimizer
[
i
].
clear_grad
()
# step lr
for
i
in
range
(
len
(
engine
.
lr_sch
)):
engine
.
lr_sch
[
i
].
step
()
if
engine
.
config
[
"Global"
].
get
(
"warmup_by_epoch"
,
False
)
is
False
:
for
i
in
range
(
len
(
engine
.
lr_sch
)):
engine
.
lr_sch
[
i
].
step
()
# below code just for logging
# update metric_for_logger
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录