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license: creativeml-openrail-m
|
5 |
+
tags:
|
6 |
+
- stable-diffusion
|
7 |
+
- stable-diffusion-diffusers
|
8 |
+
- text-to-image
|
9 |
+
- diffusers
|
10 |
+
- controlnet
|
11 |
+
- control-lora-v3
|
12 |
+
- diffusers-training
|
13 |
+
inference: true
|
14 |
+
---
|
15 |
+
|
16 |
+
<!-- This model card has been generated automatically according to the information the training script had access to. You
|
17 |
+
should probably proofread and complete it, then remove this comment. -->
|
18 |
+
|
19 |
+
|
20 |
+
# control-lora-v3
|
21 |
+
|
22 |
+
This is a collections of control-lora-v3 weights trained on runwayml/stable-diffusion-v1-5 and stabilityai/stable-diffusion-xl-base-1.0 with different types of conditioning.
|
23 |
+
You can find some example images below.
|
24 |
+
|
25 |
+
## Stable Diffusion
|
26 |
+
|
27 |
+
### Canny
|
28 |
+
<div style="display: flex; flex-wrap: wrap;">
|
29 |
+
<img src="./imgs/canny1.png" style="height:256px;" />
|
30 |
+
<img src="./imgs/canny2.png" style="height:256px;" />
|
31 |
+
<img src="./imgs/canny3.png" style="height:256px;" />
|
32 |
+
<img src="./imgs/canny4.png" style="height:256px;" />
|
33 |
+
<img src="./imgs/canny_vermeer.png" style="height:256px;" />
|
34 |
+
</div>
|
35 |
+
|
36 |
+
### OpenPose + Segmentation
|
37 |
+
|
38 |
+
This is experimental, and it doesn't work well.
|
39 |
+
|
40 |
+
<div style="display: flex; flex-wrap: wrap;">
|
41 |
+
<img src="./imgs/pose5_segmentation5.png" style="height:256px;" />
|
42 |
+
<img src="./imgs/pose6_segmentation6.png" style="height:256px;" />
|
43 |
+
<img src="./imgs/pose7_segmentation7.png" style="height:256px;" />
|
44 |
+
<img src="./imgs/pose8_segmentation8.png" style="height:256px;" />
|
45 |
+
</div>
|
46 |
+
|
47 |
+
### Depth
|
48 |
+
<div style="display: flex; flex-wrap: wrap;">
|
49 |
+
<img src="./imgs/depth1.png" style="height:256px;" />
|
50 |
+
<img src="./imgs/depth2.png" style="height:256px;" />
|
51 |
+
<img src="./imgs/depth3.png" style="height:256px;" />
|
52 |
+
<img src="./imgs/depth4.png" style="height:256px;" />
|
53 |
+
</div>
|
54 |
+
|
55 |
+
### Normal map
|
56 |
+
<div style="display: flex; flex-wrap: wrap;">
|
57 |
+
<img src="./imgs/normal1.png" style="height:256px;" />
|
58 |
+
<img src="./imgs/normal2.png" style="height:256px;" />
|
59 |
+
<img src="./imgs/normal3.png" style="height:256px;" />
|
60 |
+
<img src="./imgs/normal4.png" style="height:256px;" />
|
61 |
+
</div>
|
62 |
+
|
63 |
+
### OpenPose
|
64 |
+
<div style="display: flex; flex-wrap: wrap;">
|
65 |
+
<img src="./imgs/pose1.png" style="height:256px;" />
|
66 |
+
<img src="./imgs/pose2.png" style="height:256px;" />
|
67 |
+
<img src="./imgs/pose3.png" style="height:256px;" />
|
68 |
+
<img src="./imgs/pose4.png" style="height:256px;" />
|
69 |
+
<img src="./imgs/pose5.png" style="height:256px;" />
|
70 |
+
<img src="./imgs/pose6.png" style="height:256px;" />
|
71 |
+
<img src="./imgs/pose7.png" style="height:256px;" />
|
72 |
+
<img src="./imgs/pose8.png" style="height:256px;" />
|
73 |
+
</div>
|
74 |
+
|
75 |
+
### Segmentation
|
76 |
+
|
77 |
+
<div style="display: flex; flex-wrap: wrap;">
|
78 |
+
<img src="./imgs/segmentation1.png" style="height:256px;" />
|
79 |
+
<img src="./imgs/segmentation2.png" style="height:256px;" />
|
80 |
+
<img src="./imgs/segmentation3.png" style="height:256px;" />
|
81 |
+
<img src="./imgs/segmentation4.png" style="height:256px;" />
|
82 |
+
<img src="./imgs/segmentation5.png" style="height:256px;" />
|
83 |
+
<img src="./imgs/segmentation6.png" style="height:256px;" />
|
84 |
+
<img src="./imgs/segmentation7.png" style="height:256px;" />
|
85 |
+
<img src="./imgs/segmentation8.png" style="height:256px;" />
|
86 |
+
</div>
|
87 |
+
|
88 |
+
### Tile
|
89 |
+
<div style="display: flex; flex-wrap: wrap;">
|
90 |
+
<img src="./imgs/tile1.png" style="height:256px;" />
|
91 |
+
<img src="./imgs/tile2.png" style="height:256px;" />
|
92 |
+
<img src="./imgs/tile3.png" style="height:256px;" />
|
93 |
+
<img src="./imgs/tile4.png" style="height:256px;" />
|
94 |
+
</div>
|
95 |
+
|
96 |
+
## Stable Diffusion
|
97 |
+
|
98 |
+
### Canny
|
99 |
+
<div style="display: flex;">
|
100 |
+
<img src="./imgs/sdxl_canny1.png" style="height:256px;" />
|
101 |
+
<img src="./imgs/sdxl_canny2.png" style="height:256px;" />
|
102 |
+
<img src="./imgs/sdxl_canny3.png" style="height:256px;" />
|
103 |
+
<img src="./imgs/sdxl_canny4.png" style="height:256px;" />
|
104 |
+
<img src="./imgs/sdxl_canny_vermeer.png" style="height:256px;" />
|
105 |
+
</div>
|
106 |
+
|
107 |
+
## Intended uses & limitations
|
108 |
+
|
109 |
+
#### How to use
|
110 |
+
|
111 |
+
First clone the [control-lora-v3](https://github.com/HighCWu/control-lora-v3) and `cd` in the directory:
|
112 |
+
```sh
|
113 |
+
git clone https://github.com/HighCWu/control-lora-v3
|
114 |
+
cd control-lora-v3
|
115 |
+
```
|
116 |
+
|
117 |
+
Then run the python code。
|
118 |
+
|
119 |
+
For stable diffusion, use:
|
120 |
+
|
121 |
+
```py
|
122 |
+
# !pip install opencv-python transformers accelerate
|
123 |
+
from diffusers import UniPCMultistepScheduler
|
124 |
+
from diffusers.utils import load_image
|
125 |
+
from model import UNet2DConditionModelEx
|
126 |
+
from pipeline import StableDiffusionControlLoraV3Pipeline
|
127 |
+
import numpy as np
|
128 |
+
import torch
|
129 |
+
|
130 |
+
import cv2
|
131 |
+
from PIL import Image
|
132 |
+
|
133 |
+
# download an image
|
134 |
+
image = load_image(
|
135 |
+
"https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_image_vermeer.png"
|
136 |
+
)
|
137 |
+
image = np.array(image)
|
138 |
+
|
139 |
+
# get canny image
|
140 |
+
image = cv2.Canny(image, 100, 200)
|
141 |
+
image = image[:, :, None]
|
142 |
+
image = np.concatenate([image, image, image], axis=2)
|
143 |
+
canny_image = Image.fromarray(image)
|
144 |
+
|
145 |
+
# load stable diffusion v1-5 and control-lora-v3
|
146 |
+
unet: UNet2DConditionModelEx = UNet2DConditionModelEx.from_pretrained(
|
147 |
+
"runwayml/stable-diffusion-v1-5", subfolder="unet", torch_dtype=torch.float16
|
148 |
+
)
|
149 |
+
unet = unet.add_extra_conditions(["canny"])
|
150 |
+
pipe = StableDiffusionControlLoraV3Pipeline.from_pretrained(
|
151 |
+
"runwayml/stable-diffusion-v1-5", unet=unet, torch_dtype=torch.float16
|
152 |
+
)
|
153 |
+
# load attention processors
|
154 |
+
pipe.load_lora_weights("HighCWu/sd-control-lora-v3-canny")
|
155 |
+
|
156 |
+
# speed up diffusion process with faster scheduler and memory optimization
|
157 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
158 |
+
# remove following line if xformers is not installed
|
159 |
+
pipe.enable_xformers_memory_efficient_attention()
|
160 |
+
|
161 |
+
pipe.enable_model_cpu_offload()
|
162 |
+
|
163 |
+
# generate image
|
164 |
+
generator = torch.manual_seed(0)
|
165 |
+
image = pipe(
|
166 |
+
"futuristic-looking woman", num_inference_steps=20, generator=generator, image=canny_image
|
167 |
+
).images[0]
|
168 |
+
image.show()
|
169 |
+
```
|
170 |
+
|
171 |
+
For stable diffusion xl, use:
|
172 |
+
|
173 |
+
```py
|
174 |
+
# !pip install opencv-python transformers accelerate
|
175 |
+
from diffusers import AutoencoderKL
|
176 |
+
from diffusers.utils import load_image
|
177 |
+
from model import UNet2DConditionModelEx
|
178 |
+
from pipeline_sdxl import StableDiffusionXLControlLoraV3Pipeline
|
179 |
+
import numpy as np
|
180 |
+
import torch
|
181 |
+
|
182 |
+
import cv2
|
183 |
+
from PIL import Image
|
184 |
+
|
185 |
+
prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting"
|
186 |
+
negative_prompt = "low quality, bad quality, sketches"
|
187 |
+
|
188 |
+
# download an image
|
189 |
+
image = load_image(
|
190 |
+
"https://hf.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png"
|
191 |
+
)
|
192 |
+
|
193 |
+
# initialize the models and pipeline
|
194 |
+
unet: UNet2DConditionModelEx = UNet2DConditionModelEx.from_pretrained(
|
195 |
+
"stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", torch_dtype=torch.float16
|
196 |
+
)
|
197 |
+
unet = unet.add_extra_conditions(["canny"])
|
198 |
+
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
199 |
+
pipe = StableDiffusionXLControlLoraV3Pipeline.from_pretrained(
|
200 |
+
"stabilityai/stable-diffusion-xl-base-1.0", unet=unet, vae=vae, torch_dtype=torch.float16
|
201 |
+
)
|
202 |
+
# load attention processors
|
203 |
+
pipe.load_lora_weights("HighCWu/sdxl-control-lora-v3-canny")
|
204 |
+
pipe.enable_model_cpu_offload()
|
205 |
+
|
206 |
+
# get canny image
|
207 |
+
image = np.array(image)
|
208 |
+
image = cv2.Canny(image, 100, 200)
|
209 |
+
image = image[:, :, None]
|
210 |
+
image = np.concatenate([image, image, image], axis=2)
|
211 |
+
canny_image = Image.fromarray(image)
|
212 |
+
|
213 |
+
# generate image
|
214 |
+
image = pipe(
|
215 |
+
prompt, image=canny_image
|
216 |
+
).images[0]
|
217 |
+
image.show()
|
218 |
+
```
|
219 |
+
|
220 |
+
#### Limitations and bias
|
221 |
+
|
222 |
+
[TODO: provide examples of latent issues and potential remediations]
|
223 |
+
|
224 |
+
## Training details
|
225 |
+
|
226 |
+
[TODO: describe the data used to train the model]
|