From d5343f086689635f4444feb84925a20935b80cf9 Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Sat, 26 Mar 2022 21:17:17 +0900 Subject: [PATCH 1/2] add positional exception for giou loss https://github.com/pytorch/vision/blob/289fce29b3e2392114aadbe7a419df0f2e3ac1be/torchvision/ops/boxes.py#L301-L306 --- torchvision/ops/giou_loss.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/torchvision/ops/giou_loss.py b/torchvision/ops/giou_loss.py index 51290d6e48c..1d75e2e4b44 100644 --- a/torchvision/ops/giou_loss.py +++ b/torchvision/ops/giou_loss.py @@ -33,10 +33,17 @@ def generalized_box_iou_loss( A Metric and A Loss for Bounding Box Regression: https://arxiv.org/abs/1902.09630 """ - + x1, y1, x2, y2 = boxes1.unbind(dim=-1) x1g, y1g, x2g, y2g = boxes2.unbind(dim=-1) - + + # degenerate boxes gives inf / nan results + # so do an early check + if not ((x2 >= x1) & (y2 >= y1)).all(): + raise ValueError("Some of the input boxes1 are invalid.") + if not ((x2g >= x1g) & (y2g >= y1g)).all(): + raise ValueError("Some of the input boxes2 are invalid.") + # Intersection keypoints xkis1 = torch.max(x1, x1g) ykis1 = torch.max(y1, y1g) From 0af1703fdb81bcf7b248d4b5e021a1b7344ac0f2 Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Sat, 26 Mar 2022 21:26:58 +0900 Subject: [PATCH 2/2] clang --- torchvision/ops/giou_loss.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torchvision/ops/giou_loss.py b/torchvision/ops/giou_loss.py index 1d75e2e4b44..c320384793c 100644 --- a/torchvision/ops/giou_loss.py +++ b/torchvision/ops/giou_loss.py @@ -33,17 +33,17 @@ def generalized_box_iou_loss( A Metric and A Loss for Bounding Box Regression: https://arxiv.org/abs/1902.09630 """ - + x1, y1, x2, y2 = boxes1.unbind(dim=-1) x1g, y1g, x2g, y2g = boxes2.unbind(dim=-1) - + # degenerate boxes gives inf / nan results # so do an early check if not ((x2 >= x1) & (y2 >= y1)).all(): raise ValueError("Some of the input boxes1 are invalid.") if not ((x2g >= x1g) & (y2g >= y1g)).all(): raise ValueError("Some of the input boxes2 are invalid.") - + # Intersection keypoints xkis1 = torch.max(x1, x1g) ykis1 = torch.max(y1, y1g)