Skip to content

Commit

Permalink
Fix IOU assigners when ignore_of_thr > 0 and no pred boxes (#2135)
Browse files Browse the repository at this point in the history
* Fix IOU assigners when ignore_of_thr > 0 and no pred boxes

* remove extra brakets

* fix test linter
  • Loading branch information
Erotemic committed Feb 23, 2020
1 parent 5d75636 commit 483beb7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mmdet/core/bbox/assigners/approx_max_iou_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def assign(self,

bboxes = squares[:, :4]

if (self.ignore_iof_thr > 0) and (gt_bboxes_ignore is not None) and (
gt_bboxes_ignore.numel() > 0):
if (self.ignore_iof_thr > 0 and gt_bboxes_ignore is not None
and gt_bboxes_ignore.numel() > 0 and bboxes.numel() > 0):
if self.ignore_wrt_candidates:
ignore_overlaps = bbox_overlaps(
bboxes, gt_bboxes_ignore, mode='iof')
Expand Down
4 changes: 2 additions & 2 deletions mmdet/core/bbox/assigners/max_iou_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def assign(self, bboxes, gt_bboxes, gt_bboxes_ignore=None, gt_labels=None):
bboxes = bboxes[:, :4]
overlaps = bbox_overlaps(gt_bboxes, bboxes)

if (self.ignore_iof_thr > 0) and (gt_bboxes_ignore is not None) and (
gt_bboxes_ignore.numel() > 0):
if (self.ignore_iof_thr > 0 and gt_bboxes_ignore is not None
and gt_bboxes_ignore.numel() > 0 and bboxes.numel() > 0):
if self.ignore_wrt_candidates:
ignore_overlaps = bbox_overlaps(
bboxes, gt_bboxes_ignore, mode='iof')
Expand Down
36 changes: 36 additions & 0 deletions tests/test_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,42 @@ def test_max_iou_assigner_with_empty_boxes():
assert assign_result.labels is None


def test_max_iou_assigner_with_empty_boxes_and_ignore():
"""
Test corner case where an network might predict no boxes and ignore_iof_thr
is on
"""
self = MaxIoUAssigner(
pos_iou_thr=0.5,
neg_iou_thr=0.5,
ignore_iof_thr=0.5,
)
bboxes = torch.empty((0, 4))
gt_bboxes = torch.FloatTensor([
[0, 0, 10, 9],
[0, 10, 10, 19],
])
gt_bboxes_ignore = torch.Tensor([
[30, 30, 40, 40],
])
gt_labels = torch.LongTensor([2, 3])

# Test with gt_labels
assign_result = self.assign(
bboxes,
gt_bboxes,
gt_labels=gt_labels,
gt_bboxes_ignore=gt_bboxes_ignore)
assert len(assign_result.gt_inds) == 0
assert tuple(assign_result.labels.shape) == (0, )

# Test without gt_labels
assign_result = self.assign(
bboxes, gt_bboxes, gt_labels=None, gt_bboxes_ignore=gt_bboxes_ignore)
assert len(assign_result.gt_inds) == 0
assert assign_result.labels is None


def test_max_iou_assigner_with_empty_boxes_and_gt():
"""
Test corner case where an network might predict no boxes and no gt
Expand Down

0 comments on commit 483beb7

Please sign in to comment.