目标检测损失函数

前言

目标检测任务有很多损失函数,这里做个记录。方便以后查阅。
更多损失函数见这篇文章 【CV知识点扫盲】|损失函数篇

各种loss的实现可以查看 iscyy/yoloair/utils/loss.py



函数

IOU Loss

I O U = a r e a ( p r e d ) ∩ a r e a ( g t ) a r e a ( p r e d ) ∪ a r e a ( g t ) IOU = \frac{area(pred) \cap area(gt)}{area(pred) \cup area(gt)} IOU=area(pred)area(gt)area(pred)area(gt)
缺点: 不相交时IOU loss为0.
I O U L o s s = − l n p r e d   ∩   g t p r e d   ∪   g t IOU Loss = -ln\frac{pred ~\cap~ gt}{pred ~\cup~ gt} IOULoss=lnpred  gtpred  gt



GIOU Loss

G I O U = I O U − A r e a − p r e d   ∪   g t A r e a GIOU= IOU - \frac{Area - pred ~\cup~ gt}{Area} GIOU=IOUAreaAreapred  gt
− 1 ≤ -1 \leq 1 GIOU Loss ≤ \leq 1
其中 Area 是能够覆盖住 pred 和 gt 框的最小矩形的面积。
G I O U L o s s = 1 − G I O U GIOU Loss = 1-GIOU GIOULoss=1GIOU



DIOU Loss

G I O U = I O U − d i s t a n c e ( p r e d c e n t e r , g t c e n t e r ) 2 c 2 GIOU= IOU - \frac{distance(pred_{center}, gt_{center})^2}{c^2} GIOU=IOUc2distance(predcenter,gtcenter)2
− 1 ≤ -1 \leq 1 DIOU ≤ \leq 1
其中 c 是能够覆盖住 pred 和 gt 框的最小矩形的对角线。
G I O U L o s s = 1 − G I O U GIOU Loss = 1-GIOU GIOULoss=1GIOU



CIOU Loss

三项分别考虑重叠面积,中心点距离,宽高比
C I O U = I O U − ( d i s t a n c e ( p r e d c e n t e r , g t c e n t e r ) 2 c 2 + α v ) CIOU = IOU - (\frac{distance(pred_{center}, gt_{center})^2}{c^2}+\alpha v) CIOU=IOU(c2distance(predcenter,gtcenter)2+αv)
v = 4 π 2 ( a r c t a n ( w g t h g t ) − a r c t a n ( w h ) ) v = \frac{4}{\pi^2}(arctan(\frac{w^{gt}}{h^{gt}})-arctan(\frac{w}{h})) v=π24(arctan(hgtwgt)arctan(hw))
α = v 1 − I O U + v \alpha=\frac{v}{1-IOU+v} α=1IOU+vv
C I O U L o s s = 1 − C I O U CIOU Loss = 1-CIOU CIOULoss=1CIOU



Focal Loss

F L ( p t ) = − ( 1 − p t ) γ l o g ( p t ) FL(p_t) = -(1-p_t)^\gamma log(p_t) FL(pt)=(1pt)γlog(pt)
p t = { p i f   y = 1 1 − p o t h e r w i s e p_t = \left\{ \begin{array}{ll} p & if ~y = 1 \\ 1-p & otherwise \end{array}\right. pt={ p1pif y=1otherwise
( 1 − p t ) γ (1-p_t)^\gamma (1pt)γ可以降低易分样本的损失贡献。
3.1 YOLO系列理论合集(YOLOv1~v3)_yolov3 spp _Focal Loss讲解 33:10时刻

有时候实际代码实现中会乘多一个 α t \alpha_t αt来平衡一下loss的权重( ( 1 − p t ) γ (1-p_t)^\gamma (1pt)γ)。作为一个超参数。
F L ( p t ) = − α t ( 1 − p t ) γ l o g ( p t ) FL(p_t) = -\alpha_t(1-p_t)^\gamma log(p_t) FL(pt)=αt(1pt)γlog(pt)

注意,数据集标注要比较准确,不然这些噪声会干扰focal loss下的训练。
并且使用时需要调好参。

猜你喜欢

转载自blog.csdn.net/weixin_43850253/article/details/126326530