用于学习记录
文章目录
- 前言
- 一、SlideLoss
- 1.1 utils/loss.py
- 1.2 data/hyps/hyp.scratch-low.yaml
- 二、注意力机制 MultiSEAM
- 2.1 models/common.py
- 2.2 models/yolo.py
- 2.3 models/MultiSEAM.yaml
- 三、训练结果图
- 总结
前言
一、SlideLoss
YOLO-FaceV2: A Scale and Occlusion Aware Face Detector
1.1 utils/loss.py
插入以下代码:
import math
class SlideLoss(nn.Module):def __init__(self, loss_fcn):super(SlideLoss, self).__init__()self.loss_fcn = loss_fcnself.reduction = loss_fcn.reductionself.loss_fcn.reduction = 'none' # required to apply SL to each elementdef forward(self, pred, true, auto_iou=0.5):loss = self.loss_fcn(pred, true)if auto_iou < 0.2:auto_iou = 0.2b1 = true <= auto_iou - 0.1a1 = 1.0b2 = (true > (auto_iou - 0.1)) & (true < auto_iou)a2 = math.exp(1.0 - auto_iou)b3 = true >= auto_ioua3 = torch.exp(-(true - 1.0))modulating_weight = a1 * b1 + a2 * b2 + a3 * b3loss *= modulating_weightif self.reduction == 'mean':return loss.mean()elif self.reduction == 'sum':return loss.sum()else: # 'none'return loss
修改 class ComputeLoss
# Focal lossg = h['fl_gamma'] # focal loss gammaif g > 0:BCEcls, BCEobj = FocalLoss(BCEcls, g), FocalLoss(BCEobj, g) # 添加以下代码:Slide_Loss = h['SlideLoss']if Slide_Loss > 0:BCEcls, BCEobj = SlideLoss(BCEcls), SlideLoss(BCEobj)
1.2 data/hyps/hyp.scratch-low.yaml
添加以下内容:
SlideLoss: 0.5
二、注意力机制 MultiSEAM
2.1 models/common.py
class Residual(nn.Module):def __init__(self, fn):super(Residual, self).__init__()self.fn = fndef forwar