From 99cc35ef4fbd0155c456b9316c2a9836a2fd6b69 Mon Sep 17 00:00:00 2001 From: Chen Gen <4850090@qq.com> Date: Fri, 31 Dec 2021 05:59:29 +0800 Subject: [PATCH] Refactor/reduce G/C/D/IoU `if: else` statements (#6087) * Refactor the code to reduece else * Update metrics.py * Cleanup Co-authored-by: Cmos Co-authored-by: Glenn Jocher --- utils/metrics.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/utils/metrics.py b/utils/metrics.py index e03e1bd7460b..83defa7fd186 100644 --- a/utils/metrics.py +++ b/utils/metrics.py @@ -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