Skip to content

Preserve batch axis when padding empty image batches - #151

Open
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/empty-batch-padding
Open

sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/empty-batch-padding

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Fixes #150.

pad_to_size uses if batch: when deciding whether to include the batch axis in pad_width. A valid empty batch has size zero, so a four-dimensional NHWC or NCHW tensor receives only three padding pairs. The resulting jnp.pad call raises ValueError whenever spatial padding is needed. resize_with_crop_or_pad is affected because it calls pad_to_size.

Check batch is not None so that only genuinely unbatched images omit the leading (0, 0) padding pair. The no-padding fast path and nonempty batches retain their existing behaviour.

Six empty-batch regressions failed on unchanged master. With the fix, all seven focused tests pass, including JIT and nonempty-batch controls. The broader API, interpolation and padding test selection passed with 247 tests and 40 skips on macOS CPU. TensorFlow-dependent tests were not run locally.

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.

pad_to_size fails on empty image batches when padding is required

1 participant