Skip to content

fix a bug in inpaint pipeline when use regular text2image unet #5033

Merged
patrickvonplaten merged 4 commits intomainfrom
inpaint-test
Sep 18, 2023
Merged

fix a bug in inpaint pipeline when use regular text2image unet #5033
patrickvonplaten merged 4 commits intomainfrom
inpaint-test

Conversation

@yiyixuxu
Copy link
Copy Markdown
Collaborator

This PR fixes the bug reported here #4854

The issue comes from this line of code here - when we use inpainting pipeline with a regular text-to-image unet with 4 channels, it will only use the first image when given more than one image inputs.

I'm not sure if there is a reason it was currently done this way though.

This code currently fails but will be fixed in this PR

import PIL
import requests
import torch
from io import BytesIO

from diffusers import StableDiffusionInpaintPipeline


def download_image(url):
    response = requests.get(url)
    return PIL.Image.open(BytesIO(response.content)).convert("RGB")


imgs = []
masks = []

for img_url, mask_url in [
    ("https://i.ibb.co/DM9qbW8/x0.png","https://i.ibb.co/4TTHp6w/xxx.png"),
    ("https://i.ibb.co/J7DXFmB/x1.png","https://i.ibb.co/2gkxyWB/x1.png"),
    ("https://i.ibb.co/8gRgDYG/x3.png","https://i.ibb.co/WvZ7Q5h/x2.png"),
    ("https://i.ibb.co/KXVWT5D/x4.png","https://i.ibb.co/P5rTZFQ/x3.png")]:

    imgs.append(download_image(img_url))
    masks.append(download_image(mask_url))

pipe = StableDiffusionInpaintPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    #"rv51_inpaint",
    revision="fp16",
    torch_dtype=torch.float16,
)
pipe = pipe.to("cuda")

prompt = "Face of a yellow cat, high resolution, sitting on a park bench"

images = pipe(
    prompt=[prompt]*4, 
    image=imgs, 
    mask_image=masks,
    width=512,
    height=512
).images

for i, image in enumerate(images):
    image.save(f"yiyi_test_1_out_{i}.png")

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

HuggingFaceDocBuilderDev commented Sep 14, 2023

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

@patrickvonplaten
Copy link
Copy Markdown
Contributor

Thanks for the fix, can you also double-check if other pipelines need to be updated? E.g. controlnet inpainting and SDXL inpainting

Copy link
Copy Markdown
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.

Let's also please add one fast test :-)

@patrickvonplaten
Copy link
Copy Markdown
Contributor

Tests is flaky, let's merge

@patrickvonplaten patrickvonplaten merged commit 6886e28 into main Sep 18, 2023
@patrickvonplaten patrickvonplaten deleted the inpaint-test branch September 18, 2023 11:40
@landmann
Copy link
Copy Markdown
Contributor

Is this merged onto main 😁 ?

yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
…ngface#5033)

* fix

* fix num_images_per_prompt >1

* other pipelines

* add fast tests for inpaint pipelines

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
…ngface#5033)

* fix

* fix num_images_per_prompt >1

* other pipelines

* add fast tests for inpaint pipelines

---------

Co-authored-by: yiyixuxu <yixu310@gmail,com>
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.

4 participants