Distilling Object Detectors with Fine-grained Feature Imitation的复现

复现基于原文开源代码:https://github.com/twangnh/Distilling-Object-Detectors

代码问题和细节可以在我的github讨论:

https://github.com/HqWei/Distillation-of-Faster-rcnn

这篇文章的本质是对于目标检测在Feature Level的蒸馏的改进,你首先得实现检测的特征图层面的蒸馏,实现起来比较简单:

sup_feature=output_teacher['features'][0]
stu_feature=output['features'][0]
#model_adap是一个卷积层+Relu层:作用是把student网络的特征图变得和teacher一样,通道数相同,后面才能直接求L2距离。
stu_feature_adap=model_adap(stu_feature)

start_weigth=cfg_feature_distillation.get('start_weigth')
end_weigth=cfg_feature_distillation.get('end_weigth')

imitation_loss_weigth=start_weigth+(end_weigth-start_weigth)*(float(epoch)/max_epoch)
# imitation_loss_weigth=0.0001
#L2距离:特征图对应位置的差值的平方和
sup_loss = (torch.pow(sup_feature - stu_feature_adap, 2)).sum()
sup_loss = sup_loss * imitation_loss_weigth

然后就是本文的核心创新点:(没必要让student在整个特征图模仿teacher,只需要在GT附近模仿):

主要难点在于mask的生成,原文是:

Specifically, as shown in Fig. 2, for each ground truth box, we compute the IOU between it and all anchors, which
forms a W × H × K IOU map m. Here W and H denote width and height of the feature map, and K indicates the
K preset anchor boxes. Then we find the largest IOU value M = max(m), times the thresholding factor ψ to obtain
a filter threshold F = ψ ∗ M . With F , we filter the IOU map to keep those larger then F locations and combine them
with OR operation to get a W × H mask.

大意是:先计算GT框和所有anchor的IOU,得到一个WxHxK的IOUmap:称为m;W和H是特征图的高宽,K是单个点产生的anchor的数量(如anchor-rate为0.5,1,2;scale为2,4,8,16,32时,K=3x5),也就是一个Anchor得到一个WxH的IOU得分图,这个得分图里面每个点(WxH个)的值指的是该位置产生的anchor与GT的IOU,对比K个WxH,取k个最大的值因为只要有一个IOU大说明那地方离GT近。而最后我们得到的是一个WxH的mask,也就是只有

Distilling Image Dehazing with Heterogeneous Task Imitation method 是一种利用知识蒸馏技术来提升图像去雾性能的方法。这种方法的核心思想是通过模仿不同但相关的任务的知识,将教师模型中的有用信息转移到学生模型中[^2]。 在具体实现上,该方法设计了一个多任务学习框架,其中包含了多个辅助任务,这些任务虽然与图像去雾不直接相关,但是能够提供有助于去雾任务的特征表示。通过这种方式,学生模型不仅学习到了如何执行主要的去雾任务,同时也学会了如何处理那些辅助任务,从而增强了整体的泛化能力和鲁棒性。 此外,这种方法还采用了对抗训练策略,以进一步提高生成图像的质量。通过引入一个判别器来区分真实无雾图像和生成的去雾图像,促使生成器产生更加逼真的结果。 值得注意的是,这种基于异构任务模仿的图像去雾蒸馏方法不需要明确地估计视差,这减少了计算复杂度,并且使得算法更适合于实际应用场合。它提供了一种新颖的方式来整合来自不同领域的知识,为解决单幅图像去雾问题提供了新的视角。 由于其开源特性,研究人员可以访问提供的代码库来进行实验、调整参数以及探索更多可能的应用场景。 ```python # 示例伪代码展示基本结构 class DistillationModel: def __init__(self): # 初始化教师模型和学生模型 self.teacher_model = ... self.student_model = ... def train(self, data_loader): for images in data_loader: # 从教师模型获取软标签 teacher_outputs = self.teacher_model(images) # 学生模型前向传播 student_outputs = self.student_model(images) # 计算损失函数,包括主任务损失和辅助任务损失 loss = calculate_loss(student_outputs, teacher_outputs) # 反向传播更新权重 update_weights(loss) def calculate_loss(student, teacher): # 损失函数通常包含主任务损失和知识蒸馏损失 main_task_loss = ... kd_loss = ... return main_task_loss + kd_loss ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值