Skip to content

Commit

Permalink
Refactor/reduce G/C/D/IoU if: else statements (#6087)
Browse files Browse the repository at this point in the history
* Refactor the code to reduece else

* Update metrics.py

* Cleanup

Co-authored-by: Cmos <gen.chen@ubisoft.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
3 people committed Dec 30, 2021
1 parent 7b6938d commit affa284
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,10 @@ def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False, eps=
with torch.no_grad():
alpha = v / (v - iou + (1 + eps))
return iou - (rho2 / c2 + v * alpha) # CIoU
else:
return iou - rho2 / c2 # DIoU
else: # GIoU https://arxiv.org/pdf/1902.09630.pdf
c_area = cw * ch + eps # convex area
return iou - (c_area - union) / c_area # GIoU
else:
return iou # IoU

return iou - rho2 / c2 # DIoU
c_area = cw * ch + eps # convex area
return iou - (c_area - union) / c_area # GIoU https://arxiv.org/pdf/1902.09630.pdf
return iou # IoU

def box_iou(box1, box2):
# https://github.com/pytorch/vision/blob/master/torchvision/ops/boxes.py
Expand Down

0 comments on commit affa284

Please sign in to comment.