Giter VIP home page Giter VIP logo

controlnetinpaint's Introduction

โ™ป๏ธ ControlNetInpaint

Open In Collab

ControlNet has proven to be a great tool for guiding StableDiffusion models with image-based hints! But what about changing only a part of the image based on that hint?

๐Ÿ”ฎ The initial set of models of ControlNet were not trained to work with StableDiffusion inpainting backbone, but it turns out that the results can be pretty good!

In this repository, you will find a basic example notebook that shows how this can work. The key trick is to use the right value of the parameter controlnet_conditioning_scale - while value of 1.0 often works well, it is sometimes beneficial to bring it down a bit when the controlling image does not fit the selected text prompt very well.

๐Ÿค— Demo App on HuggingFace

Check out the open-source web demo on HuggingFace built on top of this tool: Screenshot 2023-04-16 at 11 56 29

Usage

This code is currently compatible with diffusers==0.14.0. An upgrade to the latest version can be expected in the near future (currently, some breaking changes are present in 0.15.0 that should ideally be fixed on the side of the diffusers interface).

Here's an example of how this new pipeline (StableDiffusionControlNetInpaintPipeline) is used with the core backbone of "runwayml/stable-diffusion-inpainting":

# load control net and stable diffusion v1-5
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16)
pipe = StableDiffusionControlNetInpaintPipeline.from_pretrained(
     "runwayml/stable-diffusion-inpainting", controlnet=controlnet, torch_dtype=torch.float16
 )

# speed up diffusion process with faster scheduler and memory optimization
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
# remove following line if xformers is not installed
pipe.enable_xformers_memory_efficient_attention()

pipe.to('cuda')

# generate image
generator = torch.manual_seed(0)
new_image = pipe(
    text_prompt,
    num_inference_steps=20,
    generator=generator,
    image=image,
    control_image=canny_image,
    mask_image=mask_image
).images[0]

(Full example how to get images and run the results is available in the notebook!)

Results

All results below have been generated using the ControlNet-with-Inpaint-Demo.ipynb notebook.

Let's start with turning a dog into a red panda!

Canny Edge

Prompt: "a red panda sitting on a bench"

Canny Result

HED

Prompt: "a red panda sitting on a bench"

HED Result

Scribble

Prompt: "a red panda sitting on a bench"

Canny Result

Depth

Prompt: "a red panda sitting on a bench"

Canny Result

Normal

Prompt: "a red panda sitting on a bench"

Normal Result

For the remaining modalities, the panda example doesn't really make much sense, so we use different images and prompts to illustrate the capability!

M-LSD

Prompt: "an image of a room with a city skyline view"

MLSD Result

OpenPose

Prompt: "a man in a knight armor"

Normal Result

Segmentation Mask

Prompt: "a pink eerie scary house"

Normal Result

Challenging Example ๐Ÿ•โžก๏ธ๐Ÿ”

Let's see how tuning the controlnet_conditioning_scale works out for a more challenging example of turning the dog into a cheeseburger!

In this case, we demand a large semantic leap and that requires a more subtle guide from the control image!

Cheeseburger Result

โฉ DiffusionFastForward: learn diffusion from ground up! ๐ŸŽป

If you want to learn more about the process of denoising diffusion for images, check out the open-source course DiffusionFastForward with colab notebooks where networks are trained from scratch on high-resolution data! ๐Ÿ”ฐ

Logo

Acknowledgement

There is a related excellent repository of ControlNet-for-Any-Basemodel that, among many other things, also shows similar examples of using ControlNet for inpainting. However, that definition of the pipeline is quite different, but most importantly, does not allow for controlling the controlnet_conditioning_scale as an input argument.

There are other differences, such as the fact that in this implementation, only one pipeline needs to be instantiated (as opposed to two in the other one), but the key motivation for publishing this repository is to provide a space solely focused on the application of ControlNet for inpainting.

controlnetinpaint's People

Contributors

mikonvergence avatar neelays avatar remorses avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.