Skip to content

Fix image and video resize-and-crop dimensions - #15318

Open
Lucky-Forrest923 wants to merge 2 commits into
huggingface:mainfrom
Lucky-Forrest923:fix/8911-resize-crop-rounding
Open

Lucky-Forrest923 wants to merge 2 commits into
huggingface:mainfrom
Lucky-Forrest923:fix/8911-resize-crop-rounding

Conversation

@Lucky-Forrest923

@Lucky-Forrest923 Lucky-Forrest923 commented Nov 17, 2026 •

Copy link
Copy Markdown

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. After int() truncation, center cropping starts at -1 and 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

PYTHONPATH=src python -m pytest tests/others/test_image_processor.py tests/others/test_video_processor.py -q
45 passed, 4 warnings in 0.16s

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 and git diff --check pass. Full-model inference and the full Diffusers suite were not run.

Before submitting

Who can review?

Anyone in the community is welcome to review the image and video processor changes and their regression tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes-issue size/M PR with diff < 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bugs in PixArtImageProcessor.resize_and_crop_tensor

1 participant