Fix Cutout preprocessor: correct H/W axes on non-square images#2812
Open
WatchTree-19 wants to merge 1 commit into
Open
Fix Cutout preprocessor: correct H/W axes on non-square images#2812WatchTree-19 wants to merge 1 commit into
WatchTree-19 wants to merge 1 commit into
Conversation
Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
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.
Description
Cutout.__call__(numpy/NHWC path) applies the cutout mask with the height and width slice bounds swapped:bby1/bby2are clipped toheight(valid indices for axis 1) andbbx1/bbx2are clipped towidth(valid for axis 2), but they are applied to the opposite axes. On square images this is invisible, but on non-square images it zeroes the wrong region (and, because a bound clipped toheightis used to index the width axis, the masked box can be the wrong size).Correct indexing is
x_nhwc[idx, bby1:bby2, bbx1:bbx2, :].Repro
For an 8x4 (HxW) image,
length=4, box center pinned at (row=2, col=3), the mask should cover rows[0:4] x cols[1:4]. Current code zeroes rows[1:4] x cols[0:4] instead (6/32 pixels differ).The existing tests only assert an upper bound on the count of zeroed pixels, which still holds under the swap, so they don't catch the wrong location.
Fix
Swap the slice so the height-clipped bounds index the height axis and the width-clipped bounds index the width axis.
Test
Added
test_cutout_region_location_non_square, which pins the center and asserts the exact zeroed region on a non-square image. Fails on currentdev(region mismatch /IndexError), passes with the fix; fulltest_cutout.pynumpy suite passes with no regressions. black/isort/ruff clean on the changed lines.