yolov5中使用的CiOU loss考虑了边界框回归的重叠面积、中心点距离、横纵比。但是ciou loss的公式中v反映的是横纵比的差异,而不是宽高分别与其置信度的真实差异。EIOU loss是在ciou loss的基础上提出的,加入了Focal聚焦优质的锚框。该方法最开始出自于2021年的一篇论文。
《Focal and Efficient IOU Loss for Accurate Bounding Box Regression》
地址:https://arxiv.org/abs/2101.08158
代码修改部分:
修改的主要地方是general.py文件中的bbox_iou函数,修改前的代码如下:
def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False, eps=1e-7):
# Returns the IoU of box1 to box2. box1 is 4, box2 is nx4
box2 = box2.T
# Get the coordinates of bounding boxes
if x1y1x2y2: # x1, y1, x2, y2 = box1
b1_x1, b1_y1, b1_x2, b1_y2 = box1[0], box1[1], box1[2], box1[3]
b2_x1, b2_y1, b2_x2, b2_y2 = box2[0], box2[1], box2[2], box2[3]
else: # transform from xywh to xyxy
b1_x1, b1_x2 = box1[0] - box1[2] / 2, box1[0] + box1[2] / 2
b1_y1, b1_y2