Repository navigation
Fix image and video resize-and-crop dimensions - #15318
Open
Lucky-Forrest923 wants to merge 2 commits into
Open
Lucky-Forrest923 wants to merge 2 commits into
Lucky-Forrest923 wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
What does this PR do?
Fixes #8911.
For some input sizes, floating-point rounding makes the resized dimension one pixel smaller than the crop target. Resizing an 832×1152 image to cover 960×1280, for example, computes a height of
959.9999999999999. Afterint()truncation, center cropping starts at-1and returns only one row. The video processor has the same calculation and fails when reshaping the result.Clamp the intermediate height and width to at least the target size in both processors. Inputs whose original resized dimensions already cover the target keep the same interpolation and crop behavior.
The reproduction and proposed guard come from #8911 and its image/video analysis. No new dependencies or public API changes.
Tests
Run on CPU with Python 3.14.5 and torch 2.14.1. This includes 24 new cases covering rounding failures in both dimensions, upscaling, downscaling, unchanged sizes, centered pixel values, video batch/channel/frame order, and float32/float64. Before the fix, 12 of the new cases fail and 12 pass.
make style,make fix-copies, Ruff checks andgit diff --checkpass. Full-model inference and the full Diffusers suite were not run.Before submitting
self-reviewskill on the diff?Who can review?
Anyone in the community is welcome to review the image and video processor changes and their regression tests.