From 4541c416faa433e78959c8b0915d68c5374b83e8 Mon Sep 17 00:00:00 2001 From: Cmos Date: Fri, 24 Dec 2021 12:09:41 +0800 Subject: [PATCH] Refactor the code to reduece else --- utils/metrics.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utils/metrics.py b/utils/metrics.py index e03e1bd7460b..729c0684e441 100644 --- a/utils/metrics.py +++ b/utils/metrics.py @@ -233,14 +233,14 @@ def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False, eps= v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / h2) - torch.atan(w1 / h1), 2) 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 + v * alpha) + # DIoU + return iou - rho2 / c2 + # GIoU https://arxiv.org/pdf/1902.09630.pdf + c_area = cw * ch + eps # convex area + return iou - (c_area - union) / c_area + # IoU + return iou def box_iou(box1, box2):