Repository navigation
[transforms] Handle samples without boxes in RandomRotate and RandomCrop - #2163
Merged
felixdittrich92 merged 2 commits intoOct 7, 2026
Merged
Conversation
RandomRotate and RandomCrop raised 'zero-size array to reduction operation' for an empty (0, 4) or (0, 4, 2) target. With a dict target whose classes are all empty, RandomRotate rotated the mask but returned the unrotated image, so the two no longer had the same size with expand=True.
felixdittrich92
requested changes
Oct 7, 2026
felixdittrich92
left a comment
Collaborator
There was a problem hiding this comment.
Hi @raashish1601 👋,
Thanks for the PR only a small change and we are good to merge 👍
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2163 +/- ##
==========================================
+ Coverage 97.54% 97.55% +0.01%
==========================================
Files 170 170
Lines 10658 10665 +7
==========================================
+ Hits 10396 10404 +8
+ Misses 262 261 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
felixdittrich92
approved these changes
Oct 7, 2026
felixdittrich92
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @raashish1601 LGTM 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RandomRotateandRandomCropdid not handle a sample without any box (a page with no text, or a negative sample):The dict-target paths already skip empty classes, but plain array targets went straight into the min/max reductions. And when every class of a dict target was empty,
RandomRotatereturned the original image while the mask had been rotated, so the image and mask no longer matched.Changes:
RandomRotate: an empty array target, or a dict target with only empty classes, now rotates the image (like thetarget=Nonepath) and keeps the empty target. A small_rotate_image_onlyhelper, mirroringRandomCrop._crop_image_only, is shared with thetarget=Nonepath.RandomCrop: an empty array target keeps the sample as is, the same as a dict target without any box does today.Tests: added
test_random_rotate_empty_target(box, polygon and dict targets, with a mask) andtest_random_crop_empty_target. They fail on main and pass here;pytest tests/pytorch/test_transforms_pt.pypasses (45 tests).ruff check,ruff format --checkandmypyon the changed module are clean.