From 68bfa2406d5397617af02229bb7734dfb1145e64 Mon Sep 17 00:00:00 2001 From: zytx121 <592267829@qq.com> Date: Tue, 15 Nov 2022 14:42:52 +0800 Subject: [PATCH 1/3] Update bbox_overlaps.py --- mmrotate/structures/bbox/bbox_overlaps.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mmrotate/structures/bbox/bbox_overlaps.py b/mmrotate/structures/bbox/bbox_overlaps.py index 9a4f31e89..463bc1304 100644 --- a/mmrotate/structures/bbox/bbox_overlaps.py +++ b/mmrotate/structures/bbox/bbox_overlaps.py @@ -43,6 +43,11 @@ def rbbox_overlaps(bboxes1: Tensor, clamped_bboxes1[:, 2:4].clamp_(min=1e-3) clamped_bboxes2[:, 2:4].clamp_(min=1e-3) + # resolve `rbbox_overlaps` abnormal when coordinate value is too large. + # TODO: fix in mmcv + clamped_bboxes1[:, :2].clamp_(min=1e7, max=1e7) + clamped_bboxes2[:, :2].clamp_(min=1e7, max=1e7) + return box_iou_rotated(clamped_bboxes1, clamped_bboxes2, mode, is_aligned) @@ -89,4 +94,9 @@ def fake_rbbox_overlaps(bboxes1: RotatedBoxes, clamped_bboxes1[:, 2:4].clamp_(min=1e-3) clamped_bboxes2[:, 2:4].clamp_(min=1e-3) + # resolve `rbbox_overlaps` abnormal when coordinate value is too large. + # TODO: fix in mmcv + clamped_bboxes1[:, :2].clamp_(min=1e7, max=1e7) + clamped_bboxes2[:, :2].clamp_(min=1e7, max=1e7) + return box_iou_rotated(clamped_bboxes1, clamped_bboxes2, mode, is_aligned) From 0f52706051785949dcb142a0f8e31d427af75a5b Mon Sep 17 00:00:00 2001 From: zytx121 <592267829@qq.com> Date: Tue, 15 Nov 2022 14:44:31 +0800 Subject: [PATCH 2/3] add UT --- .../test_task_modules/test_rotated_iou2d_calculator.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_models/test_task_modules/test_rotated_iou2d_calculator.py b/tests/test_models/test_task_modules/test_rotated_iou2d_calculator.py index 164d553d6..ee1b13f3d 100644 --- a/tests/test_models/test_task_modules/test_rotated_iou2d_calculator.py +++ b/tests/test_models/test_task_modules/test_rotated_iou2d_calculator.py @@ -100,6 +100,16 @@ def test_rbbox_overlaps(self): self.assertTrue(torch.all(ious >= -1) and torch.all(ious <= 1)) self.assertEqual(ious.size(), (bboxes1.size(0), bboxes2.size(0))) + # test boundary condition + bboxes1 = torch.FloatTensor([[-8.3e8, 1.4e8, 2.0e9, 3.3e1, -1.7e-1], + [8.3e8, -1.4e8, 2.0e9, 3.3e1, -1.7e-1], + [-8.3e8, -1.4e8, 2.0e9, 3.3e9, -1.7e-1]]) + bboxes2 = torch.FloatTensor([[160.0, 152.0, 2.54, 13.13, -1.5708], + [128.0, 121.0, 2.75, 17.0, -1.5708], + [136.0, 82.5, 5.8, 2.16, -1.22]]) + ious = rbbox_overlaps(bboxes1, bboxes2, 'iou') + self.assertTrue(torch.all(ious >= -1) and torch.all(ious <= 1)) + def test_fake_rbbox_overlaps_2d(self): overlap = FakeRBboxOverlaps2D() bboxes1, num_bbox = self._construct_rbbox() From 90f6cc8c24a86b0a53feb2a03711471c0fd91777 Mon Sep 17 00:00:00 2001 From: zytx121 <592267829@qq.com> Date: Tue, 15 Nov 2022 15:03:06 +0800 Subject: [PATCH 3/3] Update bbox_overlaps.py --- mmrotate/structures/bbox/bbox_overlaps.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mmrotate/structures/bbox/bbox_overlaps.py b/mmrotate/structures/bbox/bbox_overlaps.py index 463bc1304..af4fe9e8e 100644 --- a/mmrotate/structures/bbox/bbox_overlaps.py +++ b/mmrotate/structures/bbox/bbox_overlaps.py @@ -45,8 +45,8 @@ def rbbox_overlaps(bboxes1: Tensor, # resolve `rbbox_overlaps` abnormal when coordinate value is too large. # TODO: fix in mmcv - clamped_bboxes1[:, :2].clamp_(min=1e7, max=1e7) - clamped_bboxes2[:, :2].clamp_(min=1e7, max=1e7) + clamped_bboxes1[:, :2].clamp_(min=-1e7, max=1e7) + clamped_bboxes2[:, :2].clamp_(min=-1e7, max=1e7) return box_iou_rotated(clamped_bboxes1, clamped_bboxes2, mode, is_aligned) @@ -96,7 +96,7 @@ def fake_rbbox_overlaps(bboxes1: RotatedBoxes, # resolve `rbbox_overlaps` abnormal when coordinate value is too large. # TODO: fix in mmcv - clamped_bboxes1[:, :2].clamp_(min=1e7, max=1e7) - clamped_bboxes2[:, :2].clamp_(min=1e7, max=1e7) + clamped_bboxes1[:, :2].clamp_(min=-1e7, max=1e7) + clamped_bboxes2[:, :2].clamp_(min=-1e7, max=1e7) return box_iou_rotated(clamped_bboxes1, clamped_bboxes2, mode, is_aligned)