diff --git a/mmrotate/structures/bbox/bbox_overlaps.py b/mmrotate/structures/bbox/bbox_overlaps.py index 9a4f31e89..af4fe9e8e 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) 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()