Skip to content

Commit

Permalink
Refactor/reduce G/C/D/IoU if: else statements (ultralytics#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 <[email protected]>
Co-authored-by: Glenn Jocher <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2021
1 parent 65a3087 commit 99cc35e
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 99cc35e

Please sign in to comment.