Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
99f16815
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
接近 2 年 前同步成功
通知
707
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
99f16815
编写于
7月 14, 2022
作者:
D
Double_V
提交者:
GitHub
7月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix loss nan and support picodet with fgd (#6420)
上级
8d22b60a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
30 deletion
+34
-30
configs/slim/distill/retinanet_resnet101_coco_distill.yml
configs/slim/distill/retinanet_resnet101_coco_distill.yml
+2
-1
ppdet/slim/distill.py
ppdet/slim/distill.py
+32
-29
未找到文件。
configs/slim/distill/retinanet_resnet101_coco_distill.yml
浏览文件 @
99f16815
...
@@ -2,11 +2,12 @@ _BASE_: [
...
@@ -2,11 +2,12 @@ _BASE_: [
'
../../retinanet/retinanet_r101_fpn_2x_coco.yml'
,
'
../../retinanet/retinanet_r101_fpn_2x_coco.yml'
,
]
]
pretrain_weights
:
https://paddledet.bj.bcebos.com/models/
pretrained/ResNet101_pretrained
.pdparams
pretrain_weights
:
https://paddledet.bj.bcebos.com/models/
retinanet_r101_fpn_2x_coco
.pdparams
slim
:
Distill
slim
:
Distill
slim_method
:
FGD
slim_method
:
FGD
distill_loss
:
FGDFeatureLoss
distill_loss
:
FGDFeatureLoss
distill_loss_name
:
[
'
neck_f_4'
,
'
neck_f_3'
,
'
neck_f_2'
,
'
neck_f_1'
,
'
neck_f_0'
]
FGDFeatureLoss
:
FGDFeatureLoss
:
student_channels
:
256
student_channels
:
256
...
...
ppdet/slim/distill.py
浏览文件 @
99f16815
...
@@ -74,14 +74,16 @@ class FGDDistillModel(nn.Layer):
...
@@ -74,14 +74,16 @@ class FGDDistillModel(nn.Layer):
def
__init__
(
self
,
cfg
,
slim_cfg
):
def
__init__
(
self
,
cfg
,
slim_cfg
):
super
(
FGDDistillModel
,
self
).
__init__
()
super
(
FGDDistillModel
,
self
).
__init__
()
self
.
student_cfg
=
cfg
self
.
is_inherit
=
True
# build student model before load slim config
self
.
student_model
=
create
(
cfg
.
architecture
)
self
.
arch
=
cfg
.
architecture
stu_pretrain
=
cfg
[
'pretrain_weights'
]
slim_cfg
=
load_config
(
slim_cfg
)
slim_cfg
=
load_config
(
slim_cfg
)
self
.
teacher_cfg
=
slim_cfg
self
.
teacher_cfg
=
slim_cfg
self
.
loss_cfg
=
slim_cfg
self
.
loss_cfg
=
slim_cfg
self
.
is_loaded_weights
=
True
tea_pretrain
=
cfg
[
'pretrain_weights'
]
self
.
is_inherit
=
True
self
.
student_model
=
create
(
self
.
student_cfg
.
architecture
)
self
.
teacher_model
=
create
(
self
.
teacher_cfg
.
architecture
)
self
.
teacher_model
=
create
(
self
.
teacher_cfg
.
architecture
)
self
.
teacher_model
.
eval
()
self
.
teacher_model
.
eval
()
...
@@ -89,29 +91,22 @@ class FGDDistillModel(nn.Layer):
...
@@ -89,29 +91,22 @@ class FGDDistillModel(nn.Layer):
for
param
in
self
.
teacher_model
.
parameters
():
for
param
in
self
.
teacher_model
.
parameters
():
param
.
trainable
=
False
param
.
trainable
=
False
if
'pretrain_weights'
in
self
.
student_cfg
and
self
.
student_cfg
.
pretrain_weights
:
if
'pretrain_weights'
in
cfg
and
stu_pretrain
:
if
self
.
is_inherit
and
'pretrain_weights'
in
self
.
teacher_cfg
and
self
.
teacher_cfg
.
pretrain_weights
:
if
self
.
is_inherit
and
'pretrain_weights'
in
self
.
teacher_cfg
and
self
.
teacher_cfg
.
pretrain_weights
:
self
.
_load_pretrain_weights
(
self
.
student_model
,
load_pretrain_weight
(
self
.
student_model
,
self
.
teacher_cfg
.
pretrain_weights
)
self
.
teacher_cfg
.
pretrain_weights
)
print
(
"loading teacher weights to student model!"
)
logger
.
debug
(
"Inheriting! loading teacher weights to student model!"
)
self
.
_load_pretrain_weights
(
self
.
student_model
,
load_pretrain_weight
(
self
.
student_model
,
stu_pretrain
)
self
.
student_cfg
.
pretrain_weights
)
print
(
"loading student model Done"
)
if
'pretrain_weights'
in
self
.
teacher_cfg
and
self
.
teacher_cfg
.
pretrain_weights
:
if
'pretrain_weights'
in
self
.
teacher_cfg
and
self
.
teacher_cfg
.
pretrain_weights
:
self
.
_load_pretrain_weights
(
self
.
teacher_model
,
load_pretrain_weight
(
self
.
teacher_model
,
self
.
teacher_cfg
.
pretrain_weights
)
self
.
teacher_cfg
.
pretrain_weights
)
print
(
"loading teacher model Done"
)
self
.
fgd_loss_dic
=
self
.
build_loss
(
self
.
loss_cfg
.
distill_loss
)
def
_load_pretrain_weights
(
self
,
model
,
weights
):
self
.
fgd_loss_dic
=
self
.
build_loss
(
if
self
.
is_loaded_weights
:
self
.
loss_cfg
.
distill_loss
,
return
name_list
=
self
.
loss_cfg
[
'distill_loss_name'
])
self
.
start_epoch
=
0
load_pretrain_weight
(
model
,
weights
)
logger
.
debug
(
"Load weights {} to start training"
.
format
(
weights
))
def
build_loss
(
self
,
def
build_loss
(
self
,
cfg
,
cfg
,
...
@@ -137,20 +132,28 @@ class FGDDistillModel(nn.Layer):
...
@@ -137,20 +132,28 @@ class FGDDistillModel(nn.Layer):
for
idx
,
k
in
enumerate
(
self
.
fgd_loss_dic
):
for
idx
,
k
in
enumerate
(
self
.
fgd_loss_dic
):
loss_dict
[
k
]
=
self
.
fgd_loss_dic
[
k
](
s_neck_feats
[
idx
],
loss_dict
[
k
]
=
self
.
fgd_loss_dic
[
k
](
s_neck_feats
[
idx
],
t_neck_feats
[
idx
],
inputs
)
t_neck_feats
[
idx
],
inputs
)
if
self
.
arch
==
"RetinaNet"
:
loss
=
self
.
student_model
.
head
(
s_neck_feats
,
inputs
)
loss
=
self
.
student_model
.
head
(
s_neck_feats
,
inputs
)
elif
self
.
arch
==
"PicoDet"
:
loss
=
self
.
student_model
.
get_loss
()
else
:
raise
ValueError
(
f
"Unsupported model
{
self
.
arch
}
"
)
for
k
in
loss_dict
:
for
k
in
loss_dict
:
loss
[
'loss'
]
+=
loss_dict
[
k
]
loss
[
'loss'
]
+=
loss_dict
[
k
]
loss
[
k
]
=
loss_dict
[
k
]
loss
[
k
]
=
loss_dict
[
k
]
return
loss
return
loss
else
:
else
:
body_feats
=
self
.
student_model
.
backbone
(
inputs
)
body_feats
=
self
.
student_model
.
backbone
(
inputs
)
neck_feats
=
self
.
student_model
.
neck
(
body_feats
)
neck_feats
=
self
.
student_model
.
neck
(
body_feats
)
head_outs
=
self
.
student_model
.
head
(
neck_feats
)
head_outs
=
self
.
student_model
.
head
(
neck_feats
)
bbox
,
bbox_num
=
self
.
student_model
.
head
.
post_process
(
if
self
.
arch
==
"RetinaNet"
:
head_outs
,
inputs
[
'im_shape'
],
inputs
[
'scale_factor'
])
bbox
,
bbox_num
=
self
.
student_model
.
head
.
post_process
(
return
{
'bbox'
:
bbox
,
'bbox_num'
:
bbox_num
}
head_outs
,
inputs
[
'im_shape'
],
inputs
[
'scale_factor'
])
return
{
'bbox'
:
bbox
,
'bbox_num'
:
bbox_num
}
elif
self
.
arch
==
"PicoDet"
:
return
self
.
student_model
.
head
.
get_pred
()
else
:
raise
ValueError
(
f
"Unsupported model
{
self
.
arch
}
"
)
@
register
@
register
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录