CIoU protected divides (#8546)
Protected divides in IOU function to resolve https://github.com/ultralytics/yolov5/issues/8539
This commit is contained in:
1 parent
7dafd1cb29
commit
a84cd02387
1 file changed
+3
-3
+3
-3
@@ -225,8 +225,8 @@ def bbox_iou(box1, box2, xywh=True, GIoU=False, DIoU=False, CIoU=False, eps=1e-7
|
|||||||
else: # x1, y1, x2, y2 = box1
|
else: # x1, y1, x2, y2 = box1
|
||||||
b1_x1, b1_y1, b1_x2, b1_y2 = box1.chunk(4, 1)
|
b1_x1, b1_y1, b1_x2, b1_y2 = box1.chunk(4, 1)
|
||||||
b2_x1, b2_y1, b2_x2, b2_y2 = box2.chunk(4, 1)
|
b2_x1, b2_y1, b2_x2, b2_y2 = box2.chunk(4, 1)
|
||||||
w1, h1 = b1_x2 - b1_x1, b1_y2 - b1_y1 + eps
|
w1, h1 = b1_x2 - b1_x1, b1_y2 - b1_y1
|
||||||
w2, h2 = b2_x2 - b2_x1, b2_y2 - b2_y1 + eps
|
w2, h2 = b2_x2 - b2_x1, b2_y2 - b2_y1
|
||||||
|
|
||||||
# Intersection area
|
# Intersection area
|
||||||
inter = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \
|
inter = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \
|
||||||
@@ -244,7 +244,7 @@ def bbox_iou(box1, box2, xywh=True, GIoU=False, DIoU=False, CIoU=False, eps=1e-7
|
|||||||
c2 = cw ** 2 + ch ** 2 + eps # convex diagonal squared
|
c2 = cw ** 2 + ch ** 2 + eps # convex diagonal squared
|
||||||
rho2 = ((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 + (b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4 # center dist ** 2
|
rho2 = ((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 + (b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4 # center dist ** 2
|
||||||
if CIoU: # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47
|
if CIoU: # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47
|
||||||
v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / h2) - torch.atan(w1 / h1), 2)
|
v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / (h2 + eps)) - torch.atan(w1 / (h1 + eps)), 2)
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
alpha = v / (v - iou + (1 + eps))
|
alpha = v / (v - iou + (1 + eps))
|
||||||
return iou - (rho2 / c2 + v * alpha) # CIoU
|
return iou - (rho2 / c2 + v * alpha) # CIoU
|
||||||
|
|||||||
Reference in new issue
Block a user