Skip to content

Commit b2a25ff

Browse files
committed
Fix float truncation in Flux2ImageProcessor._resize_to_target_area
`_resize_to_target_area` scaled the image with `int(side * scale)`. For any input whose scaled side should be an exact integer (every square image, for one) `n * sqrt(target / n**2)` evaluates to 1023.999... in floating point for roughly 16% of sizes, so `int` truncated it to 1023. The Flux2, Flux2 Klein, Flux2 modular and Z-Image Omni pipelines then floor to a multiple of 16, so the conditioning image and default output silently became 1008x1008 instead of 1024x1024 (e.g. for a 1039x1039 input). Use `round` instead. It may exceed `target_area` by at most one pixel per side, which every caller floors away.
1 parent c5469b7 commit b2a25ff

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/diffusers/pipelines/flux2/image_processor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ def _resize_to_target_area(image: PIL.Image.Image, target_area: int = 1024 * 102
109109
image_width, image_height = image.size
110110

111111
scale = math.sqrt(target_area / (image_width * image_height))
112-
width = int(image_width * scale)
113-
height = int(image_height * scale)
112+
# Use `round` rather than `int`: truncation turns floating-point noise (e.g. 1023.999...) into a lost pixel,
113+
# which callers then floor to a smaller multiple of the VAE scale factor. Rounding may exceed `target_area` by
114+
# at most one pixel per side, which every caller floors away.
115+
width = round(image_width * scale)
116+
height = round(image_height * scale)
114117

115118
return image.resize((width, height), PIL.Image.Resampling.LANCZOS)
116119

0 commit comments

Comments
 (0)