|
67 | 67 | EXAMPLE_DOC_STRING = """ |
68 | 68 | Examples: |
69 | 69 | ```py |
70 | | - >>> # !pip install opencv-python transformers accelerate |
71 | | - >>> from diffusers import StableDiffusionXLControlNetPipeline, ControlNetModel, AutoencoderKL |
| 70 | + >>> # !pip install controlnet_aux |
| 71 | + >>> from controlnet_aux import LineartAnimeDetector |
| 72 | + >>> from diffusers import StableDiffusionXLControlNetPipeline, ControlNetUnionModel, AutoencoderKL |
| 73 | + >>> from diffusers.models.controlnets import ControlNetUnionInput |
72 | 74 | >>> from diffusers.utils import load_image |
73 | | - >>> import numpy as np |
74 | 75 | >>> import torch |
75 | | -
|
76 | | - >>> import cv2 |
77 | | - >>> from PIL import Image |
78 | | -
|
79 | | - >>> prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting" |
80 | | - >>> negative_prompt = "low quality, bad quality, sketches" |
81 | | -
|
| 76 | + >>> prompt = "A cat" |
82 | 77 | >>> # download an image |
83 | 78 | >>> image = load_image( |
84 | | - ... "https://hf.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png" |
85 | | - ... ) |
86 | | -
|
| 79 | + ... "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinsky/cat.png" |
| 80 | + ... ).resize((1024, 1024)) |
87 | 81 | >>> # initialize the models and pipeline |
88 | | - >>> controlnet_conditioning_scale = 0.5 # recommended for good generalization |
89 | | - >>> controlnet = ControlNetModel.from_pretrained( |
90 | | - ... "diffusers/controlnet-canny-sdxl-1.0", torch_dtype=torch.float16 |
| 82 | + >>> controlnet = ControlNetUnionModel.from_pretrained( |
| 83 | + ... "xinsir/controlnet-union-sdxl-1.0", torch_dtype=torch.float16 |
| 84 | + ... ) |
| 85 | + >>> vae = AutoencoderKL.from_pretrained( |
| 86 | + ... "madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16 |
91 | 87 | ... ) |
92 | | - >>> vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16) |
93 | 88 | >>> pipe = StableDiffusionXLControlNetPipeline.from_pretrained( |
94 | | - ... "stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnet, vae=vae, torch_dtype=torch.float16 |
| 89 | + ... "stabilityai/stable-diffusion-xl-base-1.0", |
| 90 | + ... controlnet=controlnet, |
| 91 | + ... vae=vae, |
| 92 | + ... torch_dtype=torch.float16, |
95 | 93 | ... ) |
96 | 94 | >>> pipe.enable_model_cpu_offload() |
97 | | -
|
98 | | - >>> # get canny image |
99 | | - >>> image = np.array(image) |
100 | | - >>> image = cv2.Canny(image, 100, 200) |
101 | | - >>> image = image[:, :, None] |
102 | | - >>> image = np.concatenate([image, image, image], axis=2) |
103 | | - >>> canny_image = Image.fromarray(image) |
104 | | -
|
| 95 | + >>> # prepare image |
| 96 | + >>> processor = LineartAnimeDetector.from_pretrained("lllyasviel/Annotators") |
| 97 | + >>> controlnet_img = processor(image, output_type="pil") |
| 98 | + >>> # set ControlNetUnion input |
| 99 | + >>> union_input = ControlNetUnionInput( |
| 100 | + ... canny=controlnet_img, |
| 101 | + ... ) |
105 | 102 | >>> # generate image |
106 | | - >>> image = pipe( |
107 | | - ... prompt, controlnet_conditioning_scale=controlnet_conditioning_scale, image=canny_image |
108 | | - ... ).images[0] |
| 103 | + >>> image = pipe(prompt, image=union_input).images[0] |
109 | 104 | ``` |
110 | 105 | """ |
111 | 106 |
|
|
0 commit comments