Fix ImagePadForOutpaintTargetSize mask scaling bug

When image and mask have different input dimensions and no downscaling
is needed (scaling_factor >= 1), the mask was not being resized to match
the image dimensions before padding, causing mismatched output sizes.

Now ensures mask dimensions match image dimensions using F.interpolate
with nearest-neighbor interpolation in both scaling branches.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
aagami 2025-08-25 14:30:50 +03:00
parent ba9153cb06
commit bc234589e6

View File

@ -1137,7 +1137,13 @@ class ImagePadForOutpaintTargetSize:
else:
# If downscaling is not needed, use the original image dimensions
image_scaled = image
mask_scaled = mask
if mask is not None:
# Ensure mask dimensions match image dimensions
mask_scaled = mask.unsqueeze(0) # Add an extra dimension for batch size
mask_scaled = F.interpolate(mask_scaled, size=(new_height, new_width), mode="nearest")
mask_scaled = mask_scaled.squeeze(0) # Remove the extra dimension after interpolation
else:
mask_scaled = mask
# Calculate how much padding is needed to reach the target dimensions
pad_top = max(0, (target_height - new_height) // 2)