Skip to content

Commit

Permalink
Fix rbbox_overlaps error (#620)
Browse files Browse the repository at this point in the history
* Update bbox_overlaps.py

* add UT

* Update bbox_overlaps.py
  • Loading branch information
zytx121 authored Nov 15, 2022
1 parent e64ab24 commit cc7e532
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mmrotate/structures/bbox/bbox_overlaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cc7e532

Please # to comment.