Skip to content

Fix Cutout preprocessor: correct H/W axes on non-square images#2812

Open
WatchTree-19 wants to merge 1 commit into
Trusted-AI:dev_1.21.0from
WatchTree-19:fix-cutout-nonsquare-axes-dev
Open

Fix Cutout preprocessor: correct H/W axes on non-square images#2812
WatchTree-19 wants to merge 1 commit into
Trusted-AI:dev_1.21.0from
WatchTree-19:fix-cutout-nonsquare-axes-dev

Conversation

@WatchTree-19

Copy link
Copy Markdown

Description

Cutout.__call__ (numpy/NHWC path) applies the cutout mask with the height and width slice bounds swapped:

x_nhwc[idx, bbx1:bbx2, bby1:bby2, :] = 0

bby1/bby2 are clipped to height (valid indices for axis 1) and bbx1/bbx2 are clipped to width (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 to height is 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 current dev (region mismatch / IndexError), passes with the fix; full test_cutout.py numpy suite passes with no regressions. black/isort/ruff clean on the changed lines.

Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
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.

1 participant