https://blog.csdn.net/WalkingSoul/article/details/101450597
GIoU Loss
参考文献:Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression
GIoU是源自IoU的一种边框预测的损失计算方法,在目标检测等领域,需要对预测边框(pre BBox)与实际标注边框(ground truth BBox)进行对比,计算损失。在Yolo算法中,给定预测值与ground truth的 x\y\w\h 进行预测,采用回归损失。但实际上,回归损失并不是该问题的最好损失函数,因为其只关注 x\y\w\w 对应的“距离”,而本质上我们想要得到 IoU 值比较大的预测框,两者联系并不大。那么为什么不直接采用IoU值作为损失函数呢? 因为一旦预测框与真实框不相交,那么IoU都为0,也就是说,在很大的范围内(不相交的区域),损失函数是没有梯度的,因此才有了GIoU Loss(Generalized Intersection over Union)。
1 为什么基于距离的损失函数不行?
如上图所示,在基于L1和L2范数的度量下,距离相同的两个框框,实际IoU值可能相差很远,所以说,这类损失函数在预测边界框时并不是一个好的选择!
2 GIoU的定义
其中:C代表包围A、B的最小体积(或面积),A、B是啥形状,C就是啥形状,你懂的; |C(A U B)| 为 C - (A U B)
性质:
1) 当IoU值为1时,GIoU 为 1,即|A U B| = |A ∩ B|;
2) Iou为0时,GIoU<=0;
3) -1<= GIoU <=1;
4) GIou <= IoU;
英文原文:For two arbitrary convex shapes (volumes) A, B ⊆ S ∈Rn, we first find the smallest convex shapes C ⊆ S ∈ Rnenclosing both A and B. For comparing two specific types of geometric shapes, C can be from the same type. For
example, two arbitrary ellipsoids, C could be the smallest ellipsoids enclosing them. Then we calculate a ratio between the volume (area) occupied by C excluding A and B and divide by the total volume (area) occupied by C. This represents a normalized measure that focuses on the empty volume (area) between A and B. Finally GIoU is attained by subtracting this ratio from the IoU value.
Similar to IoU, GIoU as a distance, e.g. LGIoU = 1 − GIoU, holding all properties of a metric such as non-negativity, identity of indiscernibles, symmetry and triangle inequality.
Similar to IoU, GIoU is invariant to the scale of the problem.
GIoU is always a lower bound for IoU, i.e. ∀A, B ⊆ S GIoU(A, B) ≤ IoU(A, B), and this lower bound becomes tighter when A and B have a stronger shape
GIoU作为损失函数
可见计算GIoU损失的方式其实就是计算GIoU,只不过最终结果返回的时1-GIoU。这是因为1-GIoU的取值范围在[0,2]上,且有一定的“距离”性质,即两个框重叠区域越大,损失越小,反之越大。