Skip to content

prepare_image in Kandinsky pipelines doesn't support torch.Tensor #11060

Description

@dk-hong

Hi, I want to report a bug in Kandinsky pipelines.

ifnotisinstance(image, list):
image= [image]
ifnotall(isinstance(i, (PIL.Image.Image, torch.Tensor)) foriinimage):
raiseValueError(
f"Input is in incorrect format: {[type(i) foriinimage]}. Currently, we only support PIL image and pytorch tensor"
)
image=torch.cat([prepare_image(i, width, height) foriinimage], dim=0)

According to the above contents, elements in image can be either PIL.Image.Image or torch.Tensor.

defprepare_image(pil_image, w=512, h=512):
pil_image=pil_image.resize((w, h), resample=Image.BICUBIC, reducing_gap=1)
arr=np.array(pil_image.convert("RGB"))
arr=arr.astype(np.float32) /127.5-1
arr=np.transpose(arr, [2, 0, 1])
image=torch.from_numpy(arr).unsqueeze(0)
returnimage

However, the prepare_image function is only for PIL.Image.Image, and does not support torch.Tensor.

Can you resolve this problem by implementing an image resize function for torch.Tensor?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions