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

problem with StableDiffusionXLControlNetInpaintPipeline #5904

Closed
D222097 opened this issue Nov 23, 2023 · 9 comments
Closed

problem with StableDiffusionXLControlNetInpaintPipeline #5904

D222097 opened this issue Nov 23, 2023 · 9 comments
Assignees
Labels
inpainting issues/questions related related to inpainting/outpainting stale Issues that haven't received updates

Comments

@D222097
Copy link

D222097 commented Nov 23, 2023

the example of StableDiffusionControlNetInpaintPipeline set the mask area to -1 when make control_image, but XL version set 0 in the example. Would that be more reasonable? Why change?

@D222097
Copy link
Author

D222097 commented Nov 23, 2023

I don't know if anyone has the same problem: when I use the controlnet-inpainting model via diffusers StableDiffusionControlNetInpaintPipeline, the result didn't follow the prompt, but the same model works well on the webui.This is only the case with XL version(no matter the mask area is set to 0 or -1)
prompt: masterpiece, best quality, ultra-detailed,8k, top quality, extremely detailed,high resolution,4k, ultra high resolution,masterpiece,best quality, a blue suv is driving down the road
raw img:
background
mask:
mask
diffusers output:
diffusers_res
webui output:
webui_res

@D222097 D222097 changed the title question about StableDiffusionXLControlNetInpaintPipeline problem with StableDiffusionXLControlNetInpaintPipeline Nov 23, 2023
@willjejones
Copy link

Currently experiencing the exact same issue. SDXL control net inpainting works as expected in the webui, but not via diffusers with this pipeline. Or at least, it does not work consistently at all.

No errors - an image is returned, but often with a barely perceivable change to the masked area. Feels as though the prompt is ignored, (although the mask seems to be used).

@D222097
Copy link
Author

D222097 commented Nov 27, 2023

I ran a more detailed test, the result was strange.: https://discuss.huggingface.co/t/problem-with-xl-controlnet-inpaint/63257

@patrickvonplaten
Copy link
Contributor

cc @yiyixuxu can you check this?

@yiyixuxu
Copy link
Collaborator

not same issue but all related to implementation difference between diffusers vs auto1111

#5808
#5498
#5600

@yiyixuxu
Copy link
Collaborator

@D222097 thanks for reporting this issue!
sorry! I'm just able to find time to look into this just now.

for this StableDiffusionControlNetInpaintPipeline example, Could you please share the exact script you used for diffusers and your auto1111 settings? I would need to know all the parameters you used, such as guidance_scale and controlnet_conditioning_scale...

Thanks again!

@D222097
Copy link
Author

D222097 commented Dec 6, 2023

@yiyixuxu Hi! Sorry for the late reply.
auto1111-webui setting:
masterpiece, best quality, the white suv is driving down the road
Steps: 30, Sampler: DPM++ 2M SDE Karras, CFG scale: 7, Seed: 529028879, Size: 1024x1024, Model hash: 0f1b80cfe8, Model: dreamshaperXL10_alpha2Xl10, Denoising strength: 0.75, Mask blur: 4, ControlNet 0: "Module: inpaint_global_harmonious, Model: car_1113_dreamshaper-xl-1-0_pretrained-cn-e80 [0a6e7ba8], Weight: 1, Resize Mode: Crop and Resize, Low Vram: False, Guidance Start: 0, Guidance End: 1, Pixel Perfect: False, Control Mode: Balanced, Save Detected Map: True", Version: v1.6.1
1701844644185_11691779-E856-44c0-8C34-24FF98BC4BFD
1701844673235_CA73D542-A565-4d81-A858-8D751D98A047
raw img:
0000395
mask:
0000395
diffusers-pipeline-result:
diffusers-pipe-res_0_0
webui-result:
00001-529028879

@D222097
Copy link
Author

D222097 commented Dec 6, 2023

diffuser pipeline script:

import os
import cv2
import numpy as np
import os
import torch
from diffusers.utils import load_image
from diffusers import (StableDiffusionXLControlNetInpaintPipeline, 
                       ControlNetModel, 
                       DDIMScheduler, 
                       DPMSolverMultistepScheduler, 
                       DDPMScheduler,
                       StableDiffusionXLInpaintPipeline,
                       StableDiffusionXLControlNetPipeline,
                       StableDiffusionXLControlNetImg2ImgPipeline)
from PIL import Image


def gen_image(data_pth, pipe, name, caption, seed):

    img_pth = f'{data_pth}/img'
    img_files = os.listdir(img_pth)
    generator = torch.Generator(device="cuda").manual_seed(seed)

    for i, img_file in enumerate(img_files):
        img_name = img_file.split('.')[0]
        img_file_pth = f'{data_pth}/img/{img_file}'
        msk_file_pth = f'{data_pth}/msk/{img_name}.png'
       
        prompt = caption

        init_image = load_image(img_file_pth)
        init_image = init_image.resize((1024, 1024))
        mask_image = load_image(msk_file_pth)
        mask_image = mask_image.resize((1024, 1024))
        control_image = make_inpaint_condition(init_image, mask_image)

        images = pipe(
            prompt=prompt,
            # negative_prompt=neg_prompt,
            num_inference_steps=30,
            num_images_per_prompt=1,
            generator=generator,
            guidance_scale=7.0,  #
            eta=1.0,
            controlnet_conditioning_scale=0.5, # 
            image=init_image,
            mask_image=mask_image,
            control_image=control_image,
            )['images']
        
        output_path = f'{data_pth}/res'
        if os.path.exists( output_path) == False:
            os.makedirs(output_path) 
        for j, image in enumerate(images) :
            image.save(os.path.join(output_path, name+"_"+str(i)+"_"+str(j)+".png") )
      
def make_inpaint_condition(image, image_mask):
    image = np.array(image.convert("RGB")).astype(np.float32) / 255.0
    image_mask = np.array(image_mask.convert("L")).astype(np.float32) / 255.0

    assert image.shape[0:1] == image_mask.shape[0:1], "image and image_mask must have the same image size"
    image[image_mask < 0.5] = -1  # set as masked pixel  ##
    image = np.expand_dims(image, 0).transpose(0, 3, 1, 2)
    image = torch.from_numpy(image)
    return image

if __name__=='__main__':
    data_pth = ""
    name = "diffusers-pipe-res"
    caption = "masterpiece, best quality, the white suv is driving down the road"
    seed = 529028879
   
    controlnet = ControlNetModel.from_pretrained(
       "", 
       torch_dtype=torch.float32
     ).to('cuda')
    pipe = StableDiffusionXLControlNetInpaintPipeline.from_pretrained(
       "/mnt/share_disk/Lykon/dreamshaper-xl-1-0", 
       controlnet=controlnet, 
       torch_dtype=torch.float32
     )
    # pipe.scheduler = DDPMScheduler.from_config(pipe.scheduler.config)
    pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
    pipe.to('cuda')
    gen_image(data_pth, pipe, name, caption, seed)

@yiyixuxu yiyixuxu added the inpainting issues/questions related related to inpainting/outpainting label Dec 7, 2023
Copy link
Contributor

github-actions bot commented Jan 3, 2024

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inpainting issues/questions related related to inpainting/outpainting stale Issues that haven't received updates
Projects
None yet
Development

No branches or pull requests

4 participants