From 09025b44dc0efd64c150116c560b7aa5f01967af Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Tue, 21 Mar 2023 14:37:59 +0530 Subject: [PATCH 1/3] add: section on multiple controlnets. Co-authored-by: William Berman --- .../pipelines/stable_diffusion/controlnet.mdx | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx b/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx index b5fa350e5f04..cfac09ccde22 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx +++ b/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx @@ -135,6 +135,123 @@ This should take only around 3-4 seconds on GPU (depending on hardware). The out +## Combining multiple conditionings + +Multiple ControlNet conditionings can be combined for a single image generation. Pass a list of ControlNets to the pipeline's constructor and a corresponding list of conditionings to `__call__`. + +When combining conditionings, it is helpful to mask conditionings such that they do not overlap. In the example, we mask the middle of the canny map where the pose conditioning is located. + +It can also be helpful to vary the `controlnet_conditioning_scales` to emphasize one conditioning over the other. + +### Canny conditioning + +The original image: + +

+ + +

+ +### Openpose conditioning + +The original image: + +

+ +

+ +Prepare the conditioning: + +```python +from controlnet_aux import OpenposeDetector +from diffusers.utils import load_image + +openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet") + +openpose_image = load_image( + "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/person.png" +) +openpose_image = openpose(openpose_image) +``` + +

+ +

+ +### Running ControlNet with multiple conditionings + +```python +from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler +import torch + +controlnet = [ + ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch.float16), + ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16), +] + +pipe = StableDiffusionControlNetPipeline.from_pretrained( + "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16 +) +pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config) + +pipe.enable_xformers_memory_efficient_attention() +pipe.enable_model_cpu_offload() + +prompt = "a giant standing in a fantasy landscape, best quality" +negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality" + +generator = torch.Generator(device="cpu").manual_seed(1) + +images = [openpose_image, canny_image] + +image = pipe( + prompt, + images, + num_inference_steps=20, + generator=generator, + negative_prompt=negative_prompt, + controlnet_conditioning_scale=[1.0, 0.8], +).images[0] + +image.save("./multi_controlnet_output.png") +``` + +

+ +

+ ## Available checkpoints ControlNet requires a *control image* in addition to the text-to-image *prompt*. From 6aa4480e3ec314af65955ec23a788e0cf5a867ad Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Thu, 23 Mar 2023 09:26:38 +0530 Subject: [PATCH 2/3] fix: docs. --- .../pipelines/stable_diffusion/controlnet.mdx | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx b/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx index cfac09ccde22..bbd165ca1e31 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx +++ b/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx @@ -147,9 +147,7 @@ It can also be helpful to vary the `controlnet_conditioning_scales` to emphasize The original image: -

-

### Openpose conditioning The original image: -

- -

+ Prepare the conditioning: @@ -206,9 +200,7 @@ openpose_image = load_image( openpose_image = openpose(openpose_image) ``` -

- -

+ ### Running ControlNet with multiple conditionings @@ -248,9 +240,7 @@ image = pipe( image.save("./multi_controlnet_output.png") ``` -

- -

+ ## Available checkpoints From 9b63a1efe824dd738e80166ec81e76b903e8138d Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Thu, 23 Mar 2023 09:33:33 +0530 Subject: [PATCH 3/3] fix: docs. --- docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx b/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx index bbd165ca1e31..aafbf5b05d79 100644 --- a/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx +++ b/docs/source/en/api/pipelines/stable_diffusion/controlnet.mdx @@ -147,7 +147,7 @@ It can also be helpful to vary the `controlnet_conditioning_scales` to emphasize The original image: - Prepare the conditioning: