Skip to content

Conversation

@raimbekovm
Copy link
Contributor

Fixes #9346

masks_to_boxes raises RuntimeError when a mask is all zeros because torch.min/max on empty tensor requires explicit dim.

This PR:

  • Handles empty masks by returning [0, 0, 0, 0] bounding boxes
  • Vectorizes the implementation (removes Python loop) for better performance on large batches
  • Adds tests for empty and mixed empty/non-empty mask batches

This is based on the approach from #8194 but fixes the empty mask handling issue that was identified there (the vectorized argmax returns [0, 0, W-1, H-1] for empty masks instead of [0, 0, 0, 0]). We detect empty masks explicitly and set their boxes to zeros.

@pytorch-bot
Copy link

pytorch-bot bot commented Jan 21, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9347

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 4f8309f with merge base 1e53952 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant