From 4541c416faa433e78959c8b0915d68c5374b83e8 Mon Sep 17 00:00:00 2001 From: Cmos Date: Fri, 24 Dec 2021 12:09:41 +0800 Subject: [PATCH 1/3] 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): From c47cb7331c33ec991abef8e7f7724f3983013439 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 30 Dec 2021 13:50:12 -0800 Subject: [PATCH 2/3] Update metrics.py --- utils/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/metrics.py b/utils/metrics.py index 729c0684e441..fbed66846e29 100644 --- a/utils/metrics.py +++ b/utils/metrics.py @@ -233,7 +233,7 @@ 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) + return iou - (rho2 / c2 + v * alpha) # CIoU # DIoU return iou - rho2 / c2 # GIoU https://arxiv.org/pdf/1902.09630.pdf From e8034afcd707b5990c2c06f629bf346e66ea42a8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 30 Dec 2021 13:55:09 -0800 Subject: [PATCH 3/3] Cleanup --- utils/metrics.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/utils/metrics.py b/utils/metrics.py index fbed66846e29..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 - # DIoU - return iou - rho2 / c2 - # GIoU https://arxiv.org/pdf/1902.09630.pdf + return iou - rho2 / c2 # DIoU c_area = cw * ch + eps # convex area - return iou - (c_area - union) / c_area - # IoU - return iou - + 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