Skip to content

Conversation

@antoche
Copy link
Contributor

@antoche antoche commented Mar 6, 2023

…peline when passing in tensor

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Mar 6, 2023

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten
Copy link
Contributor

@patil-suraj could you check this?

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

@antoche can you give a bit more background why this change, I'm a bit surprised that we need this. Usually height and width are in the same order whether it's PIL or not

@antoche
Copy link
Contributor Author

antoche commented Mar 7, 2023

Hi Patrick, the image layout on torch tensors is BxCxHxW, so image[0].shape[-2:] is in the order height, width, not width, height. On the other hand, PIL.Image.size returns 2-tuple (width, height). So the previous code was incorrectly mixing up width and height (which would only be noticed when passing in non-square tensors as input).

This change fixes this bug and makes the code consistent with the rest of the diffusers, see for example

@patrickvonplaten
Copy link
Contributor

patrickvonplaten commented Mar 9, 2023

Hey @antoche,

Thanks a lot for explaining further - you're 100% right!

For future reference, in diffusers we should always have the ... H x W ... layout for PyTorch and Numpy and always have ... W x H ... for PIL. This can also be seen by PIL automatically flipping the axis e.g.:

import numpy as np
import PIL.Image

height = 384
width = 512
image_np = np.ones(height, width, 3)

image = PIL.Image.fromarray(image_np)
image.sive
# gives (512, 384) => (width, height)

cc @yiyixuxu (this might also be important for the VAE refactor PR)

Thanks a lot for the PR @antoche !

@patrickvonplaten patrickvonplaten merged commit 75f1210 into huggingface:main Mar 9, 2023
w4ffl35 pushed a commit to w4ffl35/diffusers that referenced this pull request Apr 14, 2023
huggingface#2558)

Fixed incorrect width/height assignment in StableDiffusionDepth2ImgPipeline when passing in tensor
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
huggingface#2558)

Fixed incorrect width/height assignment in StableDiffusionDepth2ImgPipeline when passing in tensor
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
huggingface#2558)

Fixed incorrect width/height assignment in StableDiffusionDepth2ImgPipeline when passing in tensor
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.

3 participants