Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IOU assigners when ignore_of_thr > 0 and no pred boxes #2135

Merged

Conversation

Erotemic
Copy link
Contributor

When ignore_of_thr is enabled and there are no predicted bboxes, the .max function fails because the ignore_overlaps tensor is empty. The error is as follows:

~/code/mmdetection/mmdet/core/bbox/assigners/max_iou_assigner.py in assign(self, bboxes, gt_bboxes, gt_bboxes_ignore, gt_labels)
    104                 ignore_overlaps = bbox_overlaps(
    105                     bboxes, gt_bboxes_ignore, mode='iof')
--> 106                 ignore_max_overlaps, _ = ignore_overlaps.max(dim=1)
    107             else:
    108                 ignore_overlaps = bbox_overlaps(

RuntimeError: cannot perform reduction function max on tensor with no elements because the operation does not have an identity

This can be fixed by simply checking that bboxes isn't empty before running the code. I've added this fix for both approx and max iou assigners. I've also added a test, which currently passes, but will fail if the patch is removed.

@@ -119,7 +119,7 @@ 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):
gt_bboxes_ignore.numel() > 0 and bboxes.numel() > 0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! Since there are lots of conditions, we can just use one pair of brackets to hold them.

if (self.ignore_iof_thr > 0 and gt_bboxes_ignore is not None
    and gt_bboxes_ignore.numel() > 0 and bboxes.numel() > 0):
    pass

@hellock
Copy link
Member

hellock commented Feb 22, 2020

BTW, it seems that the latest ubelt (0.8.9) is broken. An import error will be raised for import ubelt.

@Erotemic
Copy link
Contributor Author

Erotemic commented Feb 23, 2020

Yes, ubelt 0.8.9 was broken. I had incorrectly used find_packages in the setup.py file. I just released 0.9.0, which (I believe) fixes the issue. I've also removed the extra parens.

@hellock hellock merged commit 483beb7 into open-mmlab:master Feb 23, 2020
mattdawkins added a commit to VIAME/mmdetection that referenced this pull request Feb 26, 2020
* jon/dev/fix_fpn2: (33 commits)
  Fix FPN upscale
  fix analyze log (open-mmlab#2150)
  Fix a documentation error in GETTING_STARTED.md (open-mmlab#2149)
  add optimizer registry (open-mmlab#2139)
  Update version to 1.1 (open-mmlab#2144)
  Fix IOU assigners when ignore_of_thr > 0 and no pred boxes (open-mmlab#2135)
  reset worker_seed (open-mmlab#2111)
  Fix issue with list of metrics in CustomDataset.evaluate (open-mmlab#2128)
  Code Release: CARAFE: Content-Aware ReAssembly of FEatures (ICCV 2019) (open-mmlab#1583)
  fixed test package (open-mmlab#2127)
  add an argument format-only to handle the json formating (open-mmlab#2114)
  fix (get_cls_results): use np.empty for empty bbox rather than np.arrary (open-mmlab#2116)
  fix (dpool): directly return empty if rois's length is 0 (open-mmlab#2099)
  fix workflow problem (open-mmlab#2103)
  Uint8 fix (open-mmlab#2105)
  Fix device bug (open-mmlab#2098)
  fix test ddp initialize (open-mmlab#2100)
  set FORCE_CUDA (open-mmlab#2097)
  Speed up sampler (open-mmlab#2094)
  Use official DDP to implement MMDDP (open-mmlab#2090)
  ...
melikovk pushed a commit to melikovk/mmdetection that referenced this pull request Feb 27, 2020
…b#2135)

* Fix IOU assigners when ignore_of_thr > 0 and no pred boxes

* remove extra brakets

* fix test linter
mattdawkins added a commit to VIAME/mmdetection that referenced this pull request Mar 13, 2020
* tag 'v1.1.0': (29 commits)
  Update version to 1.1 (open-mmlab#2144)
  Fix IOU assigners when ignore_of_thr > 0 and no pred boxes (open-mmlab#2135)
  reset worker_seed (open-mmlab#2111)
  Fix issue with list of metrics in CustomDataset.evaluate (open-mmlab#2128)
  Code Release: CARAFE: Content-Aware ReAssembly of FEatures (ICCV 2019) (open-mmlab#1583)
  fixed test package (open-mmlab#2127)
  add an argument format-only to handle the json formating (open-mmlab#2114)
  fix (get_cls_results): use np.empty for empty bbox rather than np.arrary (open-mmlab#2116)
  fix (dpool): directly return empty if rois's length is 0 (open-mmlab#2099)
  fix workflow problem (open-mmlab#2103)
  Uint8 fix (open-mmlab#2105)
  Fix device bug (open-mmlab#2098)
  fix test ddp initialize (open-mmlab#2100)
  set FORCE_CUDA (open-mmlab#2097)
  Speed up sampler (open-mmlab#2094)
  Use official DDP to implement MMDDP (open-mmlab#2090)
  log meta (open-mmlab#2086)
  fix pad_val not used in class Pad when pad to a fixed size (open-mmlab#2093)
  remove cython docs (open-mmlab#2091)
  remove new_tensor (open-mmlab#2092)
  ...
ioir123ju pushed a commit to ioir123ju/mmdetection that referenced this pull request Mar 30, 2020
…b#2135)

* Fix IOU assigners when ignore_of_thr > 0 and no pred boxes

* remove extra brakets

* fix test linter
mike112223 pushed a commit to mike112223/mmdetection that referenced this pull request Aug 25, 2020
…b#2135)

* Fix IOU assigners when ignore_of_thr > 0 and no pred boxes

* remove extra brakets

* fix test linter
liuhuiCNN pushed a commit to liuhuiCNN/mmdetection that referenced this pull request May 21, 2021
FANGAreNotGnu pushed a commit to FANGAreNotGnu/mmdetection that referenced this pull request Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants