Skip to content

Allow image_transforms.resize on normalized (out-of-range) images - #48959

Closed
tanvir-ux wants to merge 1 commit into
huggingface:mainfrom
tanvir-ux:fix/resize-normalized-images
Closed

tanvir-ux wants to merge 1 commit into
huggingface:mainfrom
tanvir-ux:fix/resize-normalized-images

Conversation

@tanvir-ux

@tanvir-ux tanvir-ux commented Sep 20, 2026

Copy link
Copy Markdown

CPU CI GPU run-slow

What does this PR do?

Fixes #34920.

I ran into ValueError when calling resize() after normalize() — the PIL conversion path only accepts [0, 1] or [0, 255], and normalized tensors are signed floats. I catch that case, temporarily map the array into [0, 1], resize, then map back. Bilinear resampling is linear, so the float field comes back in the original range. Arrays that already pass the PIL checks are unchanged (including float images in [0, 255]).

Added a regression test for normalize→resize, float-255 inputs, and a constant out-of-range image.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline and the Pull Request checks?
  • Was this discussed/approved via a Github issue? transformers.image_transforms.resize doesnot work for negative values #34920
  • Did you make sure to update the documentation with your changes according to the guidelines?
  • Did you write any new necessary tests?

Who can review?

@qubvel @amyeroberts

resize() converts through PIL, which only accepts [0, 1] or [0, 255].
After normalize(), values are signed floats, so resize raised ValueError.
Temporarily map out-of-range arrays to [0, 1], resize, then map back;
bilinear resampling is linear so the float field is preserved. Arrays
already accepted by the PIL path are unchanged.

Fixes huggingface#34920
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 35480623346:2
Result: success | Jobs: 16 | Tests: 190,597 | Failures: 0 | Duration: 17h 2m

@zucchini-nlp zucchini-nlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, not sure if we want it since this atp, a very old issue with no community interest. Also this is not the correct fix (see #34994 (review))

I'd say we close the linked PRs and the issue as not-planned

@tanvir-ux

Copy link
Copy Markdown
Author

Got it — thanks for the pointer to the earlier review. Fine to close this and the linked issue as not-planned.

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.

transformers.image_transforms.resize doesnot work for negative values

2 participants