Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: controlnet inpaint single file. #6975

Merged
merged 1 commit into from
Feb 14, 2024
Merged

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Feb 14, 2024

What does this PR do?

Fixes #6964.

Test script:

from diffusers import StableDiffusionControlNetInpaintPipeline, ControlNetModel
import numpy as np 
import cv2
from PIL import Image
from diffusers.utils import load_image
import torch 

def make_canny_condition(image):
    image = np.array(image)
    image = cv2.Canny(image, 100, 200)
    image = image[:, :, None]
    image = np.concatenate([image, image, image], axis=2)
    image = Image.fromarray(image)
    return image


controlnet = ControlNetModel.from_pretrained(
    "lllyasviel/control_v11p_sd15_canny", torch_dtype=torch.float16
)
# majicmixRealistic_v7-inpainting.safetensors comes as
# `wget https://civitai.com/api/download/models/221343 --content-disposition`
pipe = StableDiffusionControlNetInpaintPipeline.from_single_file(
    "majicmixRealistic_v7-inpainting.safetensors", 
    controlnet=controlnet, 
    torch_dtype=torch.float16,
    safety_checker=None,
    requires_safety_checker=False
).to("cuda")

init_image = load_image(
    "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_inpaint/boy.png"
)
init_image = init_image.resize((512, 512))
mask_image = load_image(
    "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_inpaint/boy_mask.png"
)
mask_image = mask_image.resize((512, 512))
control_image = make_canny_condition(init_image)

image = pipe(
    "a handsome man with ray-ban sunglasses",
    num_inference_steps=20,
    image=init_image,
    mask_image=mask_image,
    control_image=control_image
).images[0]

@sayakpaul sayakpaul requested a review from DN6 February 14, 2024 10:13
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@sayakpaul sayakpaul merged commit 37b0951 into main Feb 14, 2024
15 checks passed
@sayakpaul sayakpaul deleted the fix-sd-controlnet-inpainting-sf branch February 14, 2024 13:35
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.

StableDiffusionControlNetInpaintPipeline - does not work with 4 channel Unets
3 participants