ControlNet-for-Diffusers icon indicating copy to clipboard operation
ControlNet-for-Diffusers copied to clipboard

Do we need to do all those conversions for inpaining?

Open geekyayush opened this issue 1 year ago โ€ข 5 comments

Hello Do we need to do all those conversions mentioned under "ControlNet + Anything-v3" for inpainting?

Also, in the inpainting guide, there are these lines

# we have downloaded models locally, you can also load from huggingface
# control_sd15_seg is converted from control_sd15_seg.safetensors using instructions above
pipe_control = StableDiffusionControlNetInpaintPipeline.from_pretrained("./diffusers/control_sd15_seg",torch_dtype=torch.float16).to('cuda')
pipe_inpaint = StableDiffusionInpaintPipeline.from_pretrained("./diffusers/stable-diffusion-inpainting",torch_dtype=torch.float16).to('cuda')

Can anyone help understand what does the 2nd line means? Also, for pipe_inpaint , do we pass the stable diffusion diffuser model path?

geekyayush avatar Feb 27 '23 10:02 geekyayush

Thanks for your interest! @geekyayush

  1. Yes, you should strictly follow our instructions.
  2. pipe_inpaint is a inpainting model based on stable diffusion, we use runwayml/stable-diffusion-inpainting. We cannot directly load a stable diffusion model such as runwayml/stable-diffusion-v1-5, although they are both based on stable-diffusion-1.5, their input channels are different.

haofanwang avatar Feb 27 '23 11:02 haofanwang

Hey just following up here ! This might be a newbie misconception but if we replace the unet here do we not loose the custom model in this case the Anything v3 . Or is it really just replacing the inpainting channels ?

UglyStupidHonest avatar Feb 27 '23 13:02 UglyStupidHonest

Thanks @haofanwang !

I have another question regarding this. If I want to use an SD + Dreambooth trained inpainting fine-tuned model, then, will it work this line?

pipe_control = StableDiffusionControlNetInpaintPipeline.from_pretrained("./diffusers/control_sd15_seg",torch_dtype=torch.float16).to('cuda')
pipe_inpaint = StableDiffusionInpaintPipeline.from_pretrained("./diffusers/my-dreambooh-inpaint-model",torch_dtype=torch.float16).to('cuda')

Here, for the pipe_control, I am using the same control_sd15_seg model and for pipe_inpaint , I am using my custom trained model.

Thanks!

geekyayush avatar Feb 27 '23 17:02 geekyayush

Let me answer all you guys concerns here.

@UglyStupidHonest You are right, for now, if you want to equip ControlNet with inpainting ability, you have to replace the whole base model, which means that you cannot use anything-v3 here. I did try to only replace the input layer and keep all other layers in anything-v3, but it works bad.

@geekyayush If you inpainting model has the exact same layers as stable-diffusion-1.5, then it should work. You can just take ControlNet as a pluggable module that can insert into all stable-diffusion-1.5 based models.

haofanwang avatar Feb 27 '23 19:02 haofanwang

Is StableDiffusionControlNetInpaintPipeline currently operable? Trying the sample code in this repo with the provided input images, segmentation map, and specified models, gives the following result in my environment:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚ โ”‚ โ”‚ /ingest/ImageDiffuserService/client/inpaint_proto.py:31 in โ”‚ โ”‚ โ”‚ โ”‚ 28 # the segmentation result is generated from https://huggingface.co/spaces/hysts/ControlN โ”‚ โ”‚ 29 control_image = load_image('segmap.png') โ”‚ โ”‚ 30 โ”‚ โ”‚ โฑ 31 image = pipe_control(prompt="Face of a yellow cat, high resolution, sitting on a park be โ”‚ โ”‚ 32 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ negative_prompt="lowres, bad anatomy, worst quality, low quality", โ”‚ โ”‚ 33 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ controlnet_hint=control_image, โ”‚ โ”‚ 34 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ image=image, โ”‚ โ”‚ /home/devuser/anaconda3/envs/pytorch-env/lib/python3.8/site-packages/torch/autograd/grad_mode.py: โ”‚ โ”‚ 27 in decorate_context โ”‚ โ”‚ โ”‚ โ”‚ 24 โ”‚ โ”‚ @functools.wraps(func) โ”‚ โ”‚ 25 โ”‚ โ”‚ def decorate_context(*args, **kwargs): โ”‚ โ”‚ 26 โ”‚ โ”‚ โ”‚ with self.clone(): โ”‚ โ”‚ โฑ 27 โ”‚ โ”‚ โ”‚ โ”‚ return func(*args, **kwargs) โ”‚ โ”‚ 28 โ”‚ โ”‚ return cast(F, decorate_context) โ”‚ โ”‚ 29 โ”‚ โ”‚ โ”‚ 30 โ”‚ def _wrap_generator(self, func): โ”‚ โ”‚ โ”‚ โ”‚ /home/devuser/anaconda3/envs/pytorch-env/lib/python3.8/site-packages/diffusers/pipelines/stable_d โ”‚ โ”‚ iffusion/pipeline_stable_diffusion_controlnet_inpaint.py:793 in call โ”‚ โ”‚ โ”‚ โ”‚ 790 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ 791 โ”‚ โ”‚ โ”‚ โ”‚ if controlnet_hint is not None: โ”‚ โ”‚ 792 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ # ControlNet predict the noise residual โ”‚ โ”‚ โฑ 793 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ control = self.controlnet( โ”‚ โ”‚ 794 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ latent_model_input, t, encoder_hidden_states=prompt_embeds, cont โ”‚ โ”‚ 795 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ ) โ”‚ โ”‚ 796 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ control = [item for item in control] โ”‚ โ”‚ โ”‚ โ”‚ /home/devuser/anaconda3/envs/pytorch-env/lib/python3.8/site-packages/torch/nn/modules/module.py:1 โ”‚ โ”‚ 130 in _call_impl โ”‚ โ”‚ โ”‚ โ”‚ 1127 โ”‚ โ”‚ # this function, and just call forward. โ”‚ โ”‚ 1128 โ”‚ โ”‚ if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks o โ”‚ โ”‚ 1129 โ”‚ โ”‚ โ”‚ โ”‚ or _global_forward_hooks or _global_forward_pre_hooks): โ”‚ โ”‚ โฑ 1130 โ”‚ โ”‚ โ”‚ return forward_call(*input, **kwargs) โ”‚ โ”‚ 1131 โ”‚ โ”‚ # Do not call functions when jit is used โ”‚ โ”‚ 1132 โ”‚ โ”‚ full_backward_hooks, non_full_backward_hooks = [], [] โ”‚ โ”‚ 1133 โ”‚ โ”‚ if self._backward_hooks or _global_backward_hooks: โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ TypeError: forward() got an unexpected keyword argument 'controlnet_hint'

hyperia-elliot avatar Mar 01 '23 18:03 hyperia-elliot