File size: 10,499 Bytes
a1951a8 27d831e a1951a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
---
license: other
license_name: stabilityai-ai-community
license_link: LICENSE.md
tags:
- stable-diffusion
- controlnet
inference: true
extra_gated_prompt: >-
By clicking "Agree", you agree to the [License
Agreement](https://huggingface.co/stabilityai/stable-diffusion-3.5-large/blob/main/LICENSE.md)
and acknowledge Stability AI's [Privacy
Policy](https://stability.ai/privacy-policy).
extra_gated_fields:
Name: text
Email: text
Country: country
Organization or Affiliation: text
Receive email updates and promotions on Stability AI products, services, and research?:
type: select
options:
- 'Yes'
- 'No'
What do you intend to use the model for?:
type: select
options:
- Research
- Personal use
- Creative Professional
- Startup
- Enterprise
I agree to the License Agreement and acknowledge Stability AI's Privacy Policy: checkbox
language:
- en
pipeline_tag: text-to-image
---
# Stable Diffusion 3.5 ControlNets
![ControlNet Demo Image](canny_header.png)
## Model
This repository provides a number of ControlNet models trained for use with [Stable Diffusion 3.5 Large](https://stability.ai/news/introducing-stable-diffusion-3-5).
The following control types are available:
- Canny - Use a Canny edge map to guide the structure of the generated image. This is especially useful for illustrations, but works with all styles.
- Depth - use a depth map, generated by DepthFM, to guide generation. Some example use cases include generating architectural renderings, or texturing 3D assets.
- Blur - can be used to perform extremely high fidelity upscaling. A common use case is to tile an input image, apply the ControlNet to each tile, and merge the tiles to produce a higher resolution image. A more in-depth description of this use case is [here](https://github.com/lllyasviel/ControlNet-v1-1-nightly/issues/125).
- For Comfy users, [this extension](https://github.com/shiimizu/ComfyUI-TiledDiffusion) provides support.
- We recommend tiling the image at a tile size between 128 and 512.
All currently released ControlNets are compatible only with Stable Diffusion 3.5 Large (8b).
Additional ControlNet models, including 2B versions of the variants above, and multiple other control types, will be added to this repository in the future.
Please note: This model is released under the [Stability Community License](https://stability.ai/community-license-agreement). Visit [Stability AI](https://stability.ai/license) to learn or [contact us](https://stability.ai/enterprise) for commercial licensing details.
### License
Here are the key components of the license:
* Free for non-commercial use: Individuals and organizations can use the model free of charge for non-commercial use, including scientific research.
* Free for commercial use (up to $1M in annual revenue): Startups, small to medium-sized businesses, and creators can use the model for commercial purposes at no cost, as long as their total annual revenue is less than $1M.
* Ownership of outputs: Retain ownership of the media generated without restrictive licensing implications.
For organizations with annual revenue more than $1M, please contact us [here](https://stability.ai/enterprise) to inquire about an Enterprise License.
## Usage
For local or self-hosted use, we recommend [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for node-based UI inference, or the [standalone SD3.5 repo](https://github.com/Stability-AI/sd3.5) for programmatic use.
You can also use [🧨 Diffusers](https://github.com/huggingface/diffusers).
### Usage in ComfyUI
Please see the [ComfyUI announcement blog post](http://blog.comfy.org/sd3-5-large-controlnet/) for details on usage within Comfy, including example workflows.
### Usage in SD3.5 Standalone Repo
Install the repo:
```
git clone [email protected]:Stability-AI/sd3.5.git
pip install -r requirements.txt
```
Then, download the models and sample images like so:
```
input/canny.png
models/clip_g.safetensors
models/clip_l.safetensors
models/t5xxl.safetensors
models/sd3.5_large.safetensors
models/sd3.5_large_controlnet_canny.safetensors
```
and then you can run
```
python sd3_infer.py --controlnet_ckpt models/sd3.5_large_controlnet_canny.safetensors --controlnet_cond_image input/canny.png --prompt "An adorable fluffy pastel creature"
```
Which should give you an image like below:
![An adorable fluffy pastel creature](sample_result.png)
The conditioning image should already be preprocessed before being used as input to the standalone repo; sd3.5 does not implement the preprocessing code below.
### Usage in Diffusers 🧨
Make sure you upgrade to the latest version of diffusers: `pip install -U diffusers`. And then you can run:
```python
import torch
from diffusers import StableDiffusion3ControlNetPipeline, SD3ControlNetModel
from diffusers.utils import load_image
from diffusers.image_processor import VaeImageProcessor
class SD3CannyImageProcessor(VaeImageProcessor):
def __init__(self):
super().__init__(do_normalize=False)
def preprocess(self, image, **kwargs):
image = super().preprocess(image, **kwargs)
image = image * 255 * 0.5 + 0.5
self.config.do_normalize = True
return image
controlnet = SD3ControlNetModel.from_pretrained("diffusers-internal-dev/sd35-controlnet-canny-8b", torch_dtype=torch.float16)
pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
"stabilityai/stable-diffusion-3.5-large",
controlnet=controlnet,
torch_dtype=torch.float16
).to("cuda")
pipe.image_processor = SD3CannyImageProcessor()
control_image = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/canny.png")
prompt = "A Night time photo taken by Leica M11, portrait of a Japanese woman in a kimono, looking at the camera, Cherry blossoms"
generator = torch.Generator(device="cpu").manual_seed(0)
image = pipe(
prompt,
control_image=control_image,
controlnet_conditioning_scale=1.0,
guidance_scale=3.5,
num_inference_steps=60,
generator=generator,
max_sequence_length=77,
).images[0]
image.save(f'canny-8b.jpg')
```
### Preprocessing
Below are code snippets for preprocessing the various control image types.
#### Canny
```python
import torchvision.transforms.functional as F
# assuming img is a PIL image
img = F.to_tensor(img)
img = cv2.cvtColor(img.transpose(1, 2, 0), cv2.COLOR_RGB2GRAY)
img = cv2.Canny(img, 100, 200)
```
#### Blur
```python
import torchvision.transforms as transforms
# assuming img is a PIL image
gaussian_blur = transforms.GaussianBlur(kernel_size=50)
blurred_image = gaussian_blur(img)
```
#### Depth
```python
# install depthfm from https://github.com/CompVis/depth-fm
import torchvision.transforms as transforms
from depthfm.dfm import DepthFM
depthfm_model = DepthFM(ckpt_path=checkpoint_path)
depthfm_model.eval()
# assuming img is a PIL image
img = F.to_tensor(img)
c, h, w = img.shape
img = F.interpolate(img, (512, 512), mode='bilinear', align_corners=False)
with torch.no_grad():
img = self.depthfm_model(img, num_steps=2, ensemble_size=4)
img = F.interpolate(img, (h, w), mode='bilinear', align_corners=False)
```
### Tips
- We recommend starting with a ControlNet strength of 0.7-0.8, and adjusting as needed.
- Euler sampler and a slightly higher step count (50-60) gives best results, especially with Canny.
- Pass `--text_encoder_device <device_name>` to load the text encoders directly to VRAM, which can speed up the full inference loop at the cost of extra VRAM usage.
## Uses
All uses of the model must be in accordance with our [Acceptable Use Policy](https://stability.ai/use-policy).
### Out-of-Scope Uses
The model was not trained to be factual or true representations of people or events. As such, using the model to generate such content is out-of-scope of the abilities of this model.
### Training Data and Strategy
These models were trained on a wide variety of data, including synthetic data and filtered publicly available data.
## Safety
We believe in safe, responsible AI practices and take deliberate measures to ensure Integrity starts at the early stages of development. This means we have taken and continue to take reasonable steps to prevent the misuse of Stable Diffusion 3.5 by bad actors. For more information about our approach to Safety please visit our [Safety page](https://stability.ai/safety).
### Integrity Evaluation
Our integrity evaluation methods include structured evaluations and red-teaming testing for certain harms. Testing was conducted primarily in English and may not cover all possible harms.
### Risks identified and mitigations:
* Harmful content: We have implemented safeguards that attempt to strike the right balance between usefulness and preventing harm. However, this does not guarantee that all possible harmful content has been removed. All developers and deployers should exercise caution and implement content safety guardrails based on their specific product policies and application use cases.
* Misuse: Technical limitations and developer and end-user education can help mitigate against malicious applications of models. All users are required to adhere to our Acceptable Use Policy, including when applying fine-tuning and prompt engineering mechanisms. Please reference the Stability AI Acceptable Use Policy for information on violative uses of our products.
* Privacy violations: Developers and deployers are encouraged to adhere to privacy regulations with techniques that respect data privacy.
### Acknowledgements
- Lvmin Zhang, Anyi Rao, and Maneesh Agrawala, authors of the original [ControlNet paper](https://arxiv.org/abs/2302.05543).
- Lvmin Zhang, who also developed the [Tile ControlNet](https://huggingface.co/lllyasviel/control_v11f1e_sd15_tile), which inspired the Blur ControlNet.
- [Diffusers](https://github.com/huggingface/diffusers) library authors, whose code was referenced during development.
- [InstantX](https://github.com/instantX-research) team, whose Flux and SD3 ControlNets were also referenced during training.
- All early testers and raters of the models, and the Stability AI team.
### Contact
Please report any issues with the model or contact us:
* Safety issues: [email protected]
* Security issues: [email protected]
* Privacy issues: [email protected]
* License and general: https://stability.ai/license
* Enterprise license: https://stability.ai/enterprise |