Commit
·
5286cce
0
Parent(s):
Duplicate from ControlNet-1-1-preview/control_v11p_sd15_seg
Browse files- .gitattributes +34 -0
- README.md +312 -0
- config.json +42 -0
- control_net_seg.py +58 -0
- diffusion_pytorch_model.bin +3 -0
- diffusion_pytorch_model.fp16.bin +3 -0
- diffusion_pytorch_model.fp16.safetensors +3 -0
- diffusion_pytorch_model.safetensors +3 -0
- images/control.png +0 -0
- images/image_out.png +0 -0
- images/input.png +0 -0
- sd.png +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: openrail
|
| 3 |
+
base_model: runwayml/stable-diffusion-v1-5
|
| 4 |
+
tags:
|
| 5 |
+
- art
|
| 6 |
+
- controlnet
|
| 7 |
+
- stable-diffusion
|
| 8 |
+
duplicated_from: ControlNet-1-1-preview/control_v11p_sd15_seg
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Controlnet - v1.1 - *seg Version*
|
| 12 |
+
|
| 13 |
+
**Controlnet v1.1** is the successor model of [Controlnet v1.0](https://huggingface.co/lllyasviel/ControlNet)
|
| 14 |
+
and was released in [lllyasviel/ControlNet-v1-1](https://huggingface.co/lllyasviel/ControlNet-v1-1) by [Lvmin Zhang](https://huggingface.co/lllyasviel).
|
| 15 |
+
|
| 16 |
+
This checkpoint is a conversion of [the original checkpoint](https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_seg.pth) into `diffusers` format.
|
| 17 |
+
It can be used in combination with **Stable Diffusion**, such as [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5).
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
For more details, please also have a look at the [🧨 Diffusers docs](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/controlnet).
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
ControlNet is a neural network structure to control diffusion models by adding extra conditions.
|
| 24 |
+
|
| 25 |
+

|
| 26 |
+
|
| 27 |
+
This checkpoint corresponds to the ControlNet conditioned on **seg images**.
|
| 28 |
+
|
| 29 |
+
## Model Details
|
| 30 |
+
- **Developed by:** Lvmin Zhang, Maneesh Agrawala
|
| 31 |
+
- **Model type:** Diffusion-based text-to-image generation model
|
| 32 |
+
- **Language(s):** English
|
| 33 |
+
- **License:** [The CreativeML OpenRAIL M license](https://huggingface.co/spaces/CompVis/stable-diffusion-license) is an [Open RAIL M license](https://www.licenses.ai/blog/2022/8/18/naming-convention-of-responsible-ai-licenses), adapted from the work that [BigScience](https://bigscience.huggingface.co/) and [the RAIL Initiative](https://www.licenses.ai/) are jointly carrying in the area of responsible AI licensing. See also [the article about the BLOOM Open RAIL license](https://bigscience.huggingface.co/blog/the-bigscience-rail-license) on which our license is based.
|
| 34 |
+
- **Resources for more information:** [GitHub Repository](https://github.com/lllyasviel/ControlNet), [Paper](https://arxiv.org/abs/2302.05543).
|
| 35 |
+
- **Cite as:**
|
| 36 |
+
|
| 37 |
+
@misc{zhang2023adding,
|
| 38 |
+
title={Adding Conditional Control to Text-to-Image Diffusion Models},
|
| 39 |
+
author={Lvmin Zhang and Maneesh Agrawala},
|
| 40 |
+
year={2023},
|
| 41 |
+
eprint={2302.05543},
|
| 42 |
+
archivePrefix={arXiv},
|
| 43 |
+
primaryClass={cs.CV}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
## Introduction
|
| 47 |
+
|
| 48 |
+
Controlnet was proposed in [*Adding Conditional Control to Text-to-Image Diffusion Models*](https://arxiv.org/abs/2302.05543) by
|
| 49 |
+
Lvmin Zhang, Maneesh Agrawala.
|
| 50 |
+
|
| 51 |
+
The abstract reads as follows:
|
| 52 |
+
|
| 53 |
+
*We present a neural network structure, ControlNet, to control pretrained large diffusion models to support additional input conditions.
|
| 54 |
+
The ControlNet learns task-specific conditions in an end-to-end way, and the learning is robust even when the training dataset is small (< 50k).
|
| 55 |
+
Moreover, training a ControlNet is as fast as fine-tuning a diffusion model, and the model can be trained on a personal devices.
|
| 56 |
+
Alternatively, if powerful computation clusters are available, the model can scale to large amounts (millions to billions) of data.
|
| 57 |
+
We report that large diffusion models like Stable Diffusion can be augmented with ControlNets to enable conditional inputs like edge maps, segmentation maps, keypoints, etc.
|
| 58 |
+
This may enrich the methods to control large diffusion models and further facilitate related applications.*
|
| 59 |
+
|
| 60 |
+
## Example
|
| 61 |
+
|
| 62 |
+
It is recommended to use the checkpoint with [Stable Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5) as the checkpoint
|
| 63 |
+
has been trained on it.
|
| 64 |
+
Experimentally, the checkpoint can be used with other diffusion models such as dreamboothed stable diffusion.
|
| 65 |
+
|
| 66 |
+
**Note**: If you want to process an image to create the auxiliary conditioning, external dependencies are required as shown below:
|
| 67 |
+
|
| 68 |
+
1. Let's install `diffusers` and related packages:
|
| 69 |
+
|
| 70 |
+
```
|
| 71 |
+
$ pip install diffusers transformers accelerate
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
2. Let's define a color table we'll need later.
|
| 75 |
+
|
| 76 |
+
```py
|
| 77 |
+
import numpy as np
|
| 78 |
+
|
| 79 |
+
ada_palette = np.asarray([
|
| 80 |
+
[0, 0, 0],
|
| 81 |
+
[120, 120, 120],
|
| 82 |
+
[180, 120, 120],
|
| 83 |
+
[6, 230, 230],
|
| 84 |
+
[80, 50, 50],
|
| 85 |
+
[4, 200, 3],
|
| 86 |
+
[120, 120, 80],
|
| 87 |
+
[140, 140, 140],
|
| 88 |
+
[204, 5, 255],
|
| 89 |
+
[230, 230, 230],
|
| 90 |
+
[4, 250, 7],
|
| 91 |
+
[224, 5, 255],
|
| 92 |
+
[235, 255, 7],
|
| 93 |
+
[150, 5, 61],
|
| 94 |
+
[120, 120, 70],
|
| 95 |
+
[8, 255, 51],
|
| 96 |
+
[255, 6, 82],
|
| 97 |
+
[143, 255, 140],
|
| 98 |
+
[204, 255, 4],
|
| 99 |
+
[255, 51, 7],
|
| 100 |
+
[204, 70, 3],
|
| 101 |
+
[0, 102, 200],
|
| 102 |
+
[61, 230, 250],
|
| 103 |
+
[255, 6, 51],
|
| 104 |
+
[11, 102, 255],
|
| 105 |
+
[255, 7, 71],
|
| 106 |
+
[255, 9, 224],
|
| 107 |
+
[9, 7, 230],
|
| 108 |
+
[220, 220, 220],
|
| 109 |
+
[255, 9, 92],
|
| 110 |
+
[112, 9, 255],
|
| 111 |
+
[8, 255, 214],
|
| 112 |
+
[7, 255, 224],
|
| 113 |
+
[255, 184, 6],
|
| 114 |
+
[10, 255, 71],
|
| 115 |
+
[255, 41, 10],
|
| 116 |
+
[7, 255, 255],
|
| 117 |
+
[224, 255, 8],
|
| 118 |
+
[102, 8, 255],
|
| 119 |
+
[255, 61, 6],
|
| 120 |
+
[255, 194, 7],
|
| 121 |
+
[255, 122, 8],
|
| 122 |
+
[0, 255, 20],
|
| 123 |
+
[255, 8, 41],
|
| 124 |
+
[255, 5, 153],
|
| 125 |
+
[6, 51, 255],
|
| 126 |
+
[235, 12, 255],
|
| 127 |
+
[160, 150, 20],
|
| 128 |
+
[0, 163, 255],
|
| 129 |
+
[140, 140, 140],
|
| 130 |
+
[250, 10, 15],
|
| 131 |
+
[20, 255, 0],
|
| 132 |
+
[31, 255, 0],
|
| 133 |
+
[255, 31, 0],
|
| 134 |
+
[255, 224, 0],
|
| 135 |
+
[153, 255, 0],
|
| 136 |
+
[0, 0, 255],
|
| 137 |
+
[255, 71, 0],
|
| 138 |
+
[0, 235, 255],
|
| 139 |
+
[0, 173, 255],
|
| 140 |
+
[31, 0, 255],
|
| 141 |
+
[11, 200, 200],
|
| 142 |
+
[255, 82, 0],
|
| 143 |
+
[0, 255, 245],
|
| 144 |
+
[0, 61, 255],
|
| 145 |
+
[0, 255, 112],
|
| 146 |
+
[0, 255, 133],
|
| 147 |
+
[255, 0, 0],
|
| 148 |
+
[255, 163, 0],
|
| 149 |
+
[255, 102, 0],
|
| 150 |
+
[194, 255, 0],
|
| 151 |
+
[0, 143, 255],
|
| 152 |
+
[51, 255, 0],
|
| 153 |
+
[0, 82, 255],
|
| 154 |
+
[0, 255, 41],
|
| 155 |
+
[0, 255, 173],
|
| 156 |
+
[10, 0, 255],
|
| 157 |
+
[173, 255, 0],
|
| 158 |
+
[0, 255, 153],
|
| 159 |
+
[255, 92, 0],
|
| 160 |
+
[255, 0, 255],
|
| 161 |
+
[255, 0, 245],
|
| 162 |
+
[255, 0, 102],
|
| 163 |
+
[255, 173, 0],
|
| 164 |
+
[255, 0, 20],
|
| 165 |
+
[255, 184, 184],
|
| 166 |
+
[0, 31, 255],
|
| 167 |
+
[0, 255, 61],
|
| 168 |
+
[0, 71, 255],
|
| 169 |
+
[255, 0, 204],
|
| 170 |
+
[0, 255, 194],
|
| 171 |
+
[0, 255, 82],
|
| 172 |
+
[0, 10, 255],
|
| 173 |
+
[0, 112, 255],
|
| 174 |
+
[51, 0, 255],
|
| 175 |
+
[0, 194, 255],
|
| 176 |
+
[0, 122, 255],
|
| 177 |
+
[0, 255, 163],
|
| 178 |
+
[255, 153, 0],
|
| 179 |
+
[0, 255, 10],
|
| 180 |
+
[255, 112, 0],
|
| 181 |
+
[143, 255, 0],
|
| 182 |
+
[82, 0, 255],
|
| 183 |
+
[163, 255, 0],
|
| 184 |
+
[255, 235, 0],
|
| 185 |
+
[8, 184, 170],
|
| 186 |
+
[133, 0, 255],
|
| 187 |
+
[0, 255, 92],
|
| 188 |
+
[184, 0, 255],
|
| 189 |
+
[255, 0, 31],
|
| 190 |
+
[0, 184, 255],
|
| 191 |
+
[0, 214, 255],
|
| 192 |
+
[255, 0, 112],
|
| 193 |
+
[92, 255, 0],
|
| 194 |
+
[0, 224, 255],
|
| 195 |
+
[112, 224, 255],
|
| 196 |
+
[70, 184, 160],
|
| 197 |
+
[163, 0, 255],
|
| 198 |
+
[153, 0, 255],
|
| 199 |
+
[71, 255, 0],
|
| 200 |
+
[255, 0, 163],
|
| 201 |
+
[255, 204, 0],
|
| 202 |
+
[255, 0, 143],
|
| 203 |
+
[0, 255, 235],
|
| 204 |
+
[133, 255, 0],
|
| 205 |
+
[255, 0, 235],
|
| 206 |
+
[245, 0, 255],
|
| 207 |
+
[255, 0, 122],
|
| 208 |
+
[255, 245, 0],
|
| 209 |
+
[10, 190, 212],
|
| 210 |
+
[214, 255, 0],
|
| 211 |
+
[0, 204, 255],
|
| 212 |
+
[20, 0, 255],
|
| 213 |
+
[255, 255, 0],
|
| 214 |
+
[0, 153, 255],
|
| 215 |
+
[0, 41, 255],
|
| 216 |
+
[0, 255, 204],
|
| 217 |
+
[41, 0, 255],
|
| 218 |
+
[41, 255, 0],
|
| 219 |
+
[173, 0, 255],
|
| 220 |
+
[0, 245, 255],
|
| 221 |
+
[71, 0, 255],
|
| 222 |
+
[122, 0, 255],
|
| 223 |
+
[0, 255, 184],
|
| 224 |
+
[0, 92, 255],
|
| 225 |
+
[184, 255, 0],
|
| 226 |
+
[0, 133, 255],
|
| 227 |
+
[255, 214, 0],
|
| 228 |
+
[25, 194, 194],
|
| 229 |
+
[102, 255, 0],
|
| 230 |
+
[92, 0, 255],
|
| 231 |
+
])
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
3. Run code:
|
| 236 |
+
|
| 237 |
+
```python
|
| 238 |
+
import torch
|
| 239 |
+
import os
|
| 240 |
+
from huggingface_hub import HfApi
|
| 241 |
+
from pathlib import Path
|
| 242 |
+
from diffusers.utils import load_image
|
| 243 |
+
from PIL import Image
|
| 244 |
+
import numpy as np
|
| 245 |
+
from transformers import AutoImageProcessor, UperNetForSemanticSegmentation
|
| 246 |
+
|
| 247 |
+
from diffusers import (
|
| 248 |
+
ControlNetModel,
|
| 249 |
+
StableDiffusionControlNetPipeline,
|
| 250 |
+
UniPCMultistepScheduler,
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
image_processor = AutoImageProcessor.from_pretrained("openmmlab/upernet-convnext-small")
|
| 254 |
+
image_segmentor = UperNetForSemanticSegmentation.from_pretrained("openmmlab/upernet-convnext-small")
|
| 255 |
+
|
| 256 |
+
checkpoint = "lllyasviel/control_v11p_sd15_seg"
|
| 257 |
+
|
| 258 |
+
image = load_image(
|
| 259 |
+
"https://huggingface.co/lllyasviel/control_v11p_sd15_seg/resolve/main/images/input.png"
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
prompt = "old house in stormy weather with rain and wind"
|
| 263 |
+
|
| 264 |
+
pixel_values = image_processor(image, return_tensors="pt").pixel_values
|
| 265 |
+
with torch.no_grad():
|
| 266 |
+
outputs = image_segmentor(pixel_values)
|
| 267 |
+
seg = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
| 268 |
+
color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8) # height, width, 3
|
| 269 |
+
for label, color in enumerate(ada_palette):
|
| 270 |
+
color_seg[seg == label, :] = color
|
| 271 |
+
color_seg = color_seg.astype(np.uint8)
|
| 272 |
+
control_image = Image.fromarray(color_seg)
|
| 273 |
+
|
| 274 |
+
control_image.save("./images/control.png")
|
| 275 |
+
|
| 276 |
+
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
|
| 277 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
| 278 |
+
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 282 |
+
pipe.enable_model_cpu_offload()
|
| 283 |
+
|
| 284 |
+
generator = torch.manual_seed(0)
|
| 285 |
+
image = pipe(prompt, num_inference_steps=30, generator=generator, image=control_image).images[0]
|
| 286 |
+
|
| 287 |
+
image.save('images/image_out.png')
|
| 288 |
+
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+

|
| 292 |
+
|
| 293 |
+

|
| 294 |
+
|
| 295 |
+

|
| 296 |
+
|
| 297 |
+
## Other released checkpoints v1-1
|
| 298 |
+
|
| 299 |
+
The authors released 14 different checkpoints, each trained with [Stable Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5)
|
| 300 |
+
on a different type of conditioning:
|
| 301 |
+
|
| 302 |
+
| Model Name | Control Image Overview| Control Image Example | Generated Image Example |
|
| 303 |
+
|---|---|---|---|
|
| 304 |
+
TODO
|
| 305 |
+
|
| 306 |
+
### Training
|
| 307 |
+
|
| 308 |
+
TODO
|
| 309 |
+
|
| 310 |
+
### Blog post
|
| 311 |
+
|
| 312 |
+
For more information, please also have a look at the [Diffusers ControlNet Blog Post](https://huggingface.co/blog/controlnet).
|
config.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "ControlNetModel",
|
| 3 |
+
"_diffusers_version": "0.16.0.dev0",
|
| 4 |
+
"_name_or_path": "/home/patrick/controlnet_v1_1/control_v11p_sd15_seg",
|
| 5 |
+
"act_fn": "silu",
|
| 6 |
+
"attention_head_dim": 8,
|
| 7 |
+
"block_out_channels": [
|
| 8 |
+
320,
|
| 9 |
+
640,
|
| 10 |
+
1280,
|
| 11 |
+
1280
|
| 12 |
+
],
|
| 13 |
+
"class_embed_type": null,
|
| 14 |
+
"conditioning_embedding_out_channels": [
|
| 15 |
+
16,
|
| 16 |
+
32,
|
| 17 |
+
96,
|
| 18 |
+
256
|
| 19 |
+
],
|
| 20 |
+
"controlnet_conditioning_channel_order": "rgb",
|
| 21 |
+
"cross_attention_dim": 768,
|
| 22 |
+
"down_block_types": [
|
| 23 |
+
"CrossAttnDownBlock2D",
|
| 24 |
+
"CrossAttnDownBlock2D",
|
| 25 |
+
"CrossAttnDownBlock2D",
|
| 26 |
+
"DownBlock2D"
|
| 27 |
+
],
|
| 28 |
+
"downsample_padding": 1,
|
| 29 |
+
"flip_sin_to_cos": true,
|
| 30 |
+
"freq_shift": 0,
|
| 31 |
+
"in_channels": 4,
|
| 32 |
+
"layers_per_block": 2,
|
| 33 |
+
"mid_block_scale_factor": 1,
|
| 34 |
+
"norm_eps": 1e-05,
|
| 35 |
+
"norm_num_groups": 32,
|
| 36 |
+
"num_class_embeds": null,
|
| 37 |
+
"only_cross_attention": false,
|
| 38 |
+
"projection_class_embeddings_input_dim": null,
|
| 39 |
+
"resnet_time_scale_shift": "default",
|
| 40 |
+
"upcast_attention": false,
|
| 41 |
+
"use_linear_projection": false
|
| 42 |
+
}
|
control_net_seg.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import torch
|
| 3 |
+
import os
|
| 4 |
+
from huggingface_hub import HfApi
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from diffusers.utils import load_image
|
| 7 |
+
from transformers import AutoImageProcessor, UperNetForSemanticSegmentation
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
from diffusers import (
|
| 12 |
+
ControlNetModel,
|
| 13 |
+
StableDiffusionControlNetPipeline,
|
| 14 |
+
UniPCMultistepScheduler,
|
| 15 |
+
)
|
| 16 |
+
import sys
|
| 17 |
+
|
| 18 |
+
image_processor = AutoImageProcessor.from_pretrained("openmmlab/upernet-convnext-small")
|
| 19 |
+
image_segmentor = UperNetForSemanticSegmentation.from_pretrained("openmmlab/upernet-convnext-small")
|
| 20 |
+
|
| 21 |
+
image = load_image("https://huggingface.co/lllyasviel/sd-controlnet-seg/resolve/main/images/house.png").convert('RGB')
|
| 22 |
+
|
| 23 |
+
prompt = "old house in stormy weather with rain and wind"
|
| 24 |
+
|
| 25 |
+
pixel_values = image_processor(image, return_tensors="pt").pixel_values
|
| 26 |
+
with torch.no_grad():
|
| 27 |
+
outputs = image_segmentor(pixel_values)
|
| 28 |
+
seg = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[image.size[::-1]])[0]
|
| 29 |
+
color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8) # height, width, 3
|
| 30 |
+
for label, color in enumerate(ada_palette):
|
| 31 |
+
color_seg[seg == label, :] = color
|
| 32 |
+
color_seg = color_seg.astype(np.uint8)
|
| 33 |
+
image = Image.fromarray(color_seg)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
|
| 37 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
| 38 |
+
"runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 42 |
+
pipe.enable_model_cpu_offload()
|
| 43 |
+
|
| 44 |
+
generator = torch.manual_seed(0)
|
| 45 |
+
out_image = pipe(prompt, num_inference_steps=30, generator=generator, image=image).images[0]
|
| 46 |
+
|
| 47 |
+
path = os.path.join(Path.home(), "images", "aa.png")
|
| 48 |
+
out_image.save(path)
|
| 49 |
+
|
| 50 |
+
api = HfApi()
|
| 51 |
+
|
| 52 |
+
api.upload_file(
|
| 53 |
+
path_or_fileobj=path,
|
| 54 |
+
path_in_repo=path.split("/")[-1],
|
| 55 |
+
repo_id="patrickvonplaten/images",
|
| 56 |
+
repo_type="dataset",
|
| 57 |
+
)
|
| 58 |
+
print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")
|
diffusion_pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4397ad13ff43760023ad5f7b13969731e52c0d23cc1c609fcb4b25da2c00be0b
|
| 3 |
+
size 1445254969
|
diffusion_pytorch_model.fp16.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:90dcbc018c19a01dc146a3062227a35142f700031abd5f0a5385447f469cbce2
|
| 3 |
+
size 722698343
|
diffusion_pytorch_model.fp16.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:23809d298edb48bf97ce95c6b8c4a69a749e57bf3838d866fbdc45f8fa11f6f4
|
| 3 |
+
size 722598642
|
diffusion_pytorch_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68291d493d0d75df67fe931c753c9b204cf3863509d5471b5eb64e5f0f2b4b38
|
| 3 |
+
size 1445157124
|
images/control.png
ADDED
|
images/image_out.png
ADDED
|
images/input.png
ADDED
|
sd.png
ADDED
|