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false
|
7 |
+
---
|
8 |
+
|
9 |
+
# Stable Diffusion v1 Model Card
|
10 |
+
This model card focuses on the model associated with the Stable Diffusion model, available [here](https://github.com/CompVis/stable-diffusion).
|
11 |
+
|
12 |
+
## Model Details
|
13 |
+
- **Developed by:** Robin Rombach, Patrick Esser
|
14 |
+
- **Model type:** Diffusion-based text-to-image generation model
|
15 |
+
- **Language(s):** English
|
16 |
+
- **License:** [Proprietary](LICENSE)
|
17 |
+
- **Model Description:** This is a model that can be used to generate and modify images based on text prompts. It is a [Latent Diffusion Model](https://arxiv.org/abs/2112.10752) that uses a fixed, pretrained text encoder ([CLIP ViT-L/14](https://arxiv.org/abs/2103.00020)) as suggested in the [Imagen paper](https://arxiv.org/abs/2205.11487).
|
18 |
+
- **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).
|
19 |
+
- **Cite as:**
|
20 |
+
|
21 |
+
@InProceedings{Rombach_2022_CVPR,
|
22 |
+
author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
|
23 |
+
title = {High-Resolution Image Synthesis With Latent Diffusion Models},
|
24 |
+
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
25 |
+
month = {June},
|
26 |
+
year = {2022},
|
27 |
+
pages = {10684-10695}
|
28 |
+
}
|
29 |
+
|
30 |
+
## Usage examples
|
31 |
+
|
32 |
+
```bash
|
33 |
+
pip install --upgrade diffusers transformers scipy
|
34 |
+
```
|
35 |
+
|
36 |
+
Run this command to log in with your HF Hub token if you haven't before:
|
37 |
+
```bash
|
38 |
+
huggingface-cli login
|
39 |
+
```
|
40 |
+
|
41 |
+
Running the pipeline with the default PLMS scheduler:
|
42 |
+
```python
|
43 |
+
from torch import autocast
|
44 |
+
from diffusers import StableDiffusionPipeline
|
45 |
+
|
46 |
+
model_id = "CompVis/stable-diffusion-v1-2-diffusers"
|
47 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
|
48 |
+
|
49 |
+
prompt = "a photograph of an astronaut riding a horse"
|
50 |
+
with autocast("cuda"):
|
51 |
+
image = pipe(prompt, guidance_scale=7)["sample"][0] # image here is in PIL format
|
52 |
+
|
53 |
+
image.save(f"astronaut_rides_horse.png")
|
54 |
+
```
|
55 |
+
|
56 |
+
To swap out the noise scheduler, pass it to `from_pretrained`:
|
57 |
+
|
58 |
+
```python
|
59 |
+
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
|
60 |
+
|
61 |
+
model_id = "CompVis/stable-diffusion-v1-2-diffusers"
|
62 |
+
# Use the K-LMS scheduler here instead
|
63 |
+
scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
|
64 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, use_auth_token=True)
|
65 |
+
```
|
66 |
+
|
67 |
+
|
68 |
+
# Uses
|
69 |
+
|
70 |
+
## Direct Use
|
71 |
+
The model is intended for research purposes only. Possible research areas and
|
72 |
+
tasks include
|
73 |
+
|
74 |
+
- Safe deployment of models which have the potential to generate harmful content.
|
75 |
+
- Probing and understanding the limitations and biases of generative models.
|
76 |
+
- Generation of artworks and use in design and other artistic processes.
|
77 |
+
- Applications in educational or creative tools.
|
78 |
+
- Research on generative models.
|
79 |
+
|
80 |
+
Excluded uses are described below.
|
81 |
+
|
82 |
+
### Misuse, Malicious Use, and Out-of-Scope Use
|
83 |
+
_Note: This section is taken from the [DALLE-MINI model card](https://huggingface.co/dalle-mini/dalle-mini), but applies in the same way to Stable Diffusion v1_.
|
84 |
+
|
85 |
+
|
86 |
+
The model should not be used to intentionally create or disseminate images that create hostile or alienating environments for people. This includes generating images that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes.
|
87 |
+
#### Out-of-Scope Use
|
88 |
+
The model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model.
|
89 |
+
#### Misuse and Malicious Use
|
90 |
+
Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
|
91 |
+
|
92 |
+
- Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
|
93 |
+
- Intentionally promoting or propagating discriminatory content or harmful stereotypes.
|
94 |
+
- Impersonating individuals without their consent.
|
95 |
+
- Sexual content without consent of the people who might see it.
|
96 |
+
- Mis- and disinformation
|
97 |
+
- Representations of egregious violence and gore
|
98 |
+
- Sharing of copyrighted or licensed material in violation of its terms of use.
|
99 |
+
- Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
|
100 |
+
|
101 |
+
## Limitations and Bias
|
102 |
+
|
103 |
+
### Limitations
|
104 |
+
|
105 |
+
- The model does not achieve perfect photorealism
|
106 |
+
- The model cannot render legible text
|
107 |
+
- The model does not perform well on more difficult tasks which involve compositionality, such as rendering an image corresponding to “A red cube on top of a blue sphere”
|
108 |
+
- Faces and people in general may not be generated properly.
|
109 |
+
- The model was trained mainly with English captions and will not work as well in other languages.
|
110 |
+
- The autoencoding part of the model is lossy
|
111 |
+
- The model was trained on a large-scale dataset
|
112 |
+
[LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
|
113 |
+
and is not fit for product use without additional safety mechanisms and
|
114 |
+
considerations.
|
115 |
+
|
116 |
+
### Bias
|
117 |
+
While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
|
118 |
+
Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
|
119 |
+
which consists of images that are primarily limited to English descriptions.
|
120 |
+
Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
|
121 |
+
This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
|
122 |
+
ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
|
123 |
+
|
124 |
+
|
125 |
+
## Training
|
126 |
+
|
127 |
+
**Training Data**
|
128 |
+
The model developers used the following dataset for training the model:
|
129 |
+
|
130 |
+
- LAION-2B (en) and subsets thereof (see next section)
|
131 |
+
|
132 |
+
**Training Procedure**
|
133 |
+
Stable Diffusion v1 is a latent diffusion model which combines an autoencoder with a diffusion model that is trained in the latent space of the autoencoder. During training,
|
134 |
+
|
135 |
+
- Images are encoded through an encoder, which turns images into latent representations. The autoencoder uses a relative downsampling factor of 8 and maps images of shape H x W x 3 to latents of shape H/f x W/f x 4
|
136 |
+
- Text prompts are encoded through a ViT-L/14 text-encoder.
|
137 |
+
- The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
|
138 |
+
- The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.
|
139 |
+
|
140 |
+
We currently provide three checkpoints, `sd-v1-1.ckpt`, `sd-v1-2.ckpt` and `sd-v1-3.ckpt`,
|
141 |
+
which were trained as follows,
|
142 |
+
|
143 |
+
- `sd-v1-1.ckpt`: 237k steps at resolution `256x256` on [laion2B-en](https://huggingface.co/datasets/laion/laion2B-en).
|
144 |
+
194k steps at resolution `512x512` on [laion-high-resolution](https://huggingface.co/datasets/laion/laion-high-resolution) (170M examples from LAION-5B with resolution `>= 1024x1024`).
|
145 |
+
- `sd-v1-2.ckpt`: Resumed from `sd-v1-1.ckpt`.
|
146 |
+
515k steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,
|
147 |
+
filtered to images with an original size `>= 512x512`, estimated aesthetics score `> 5.0`, and an estimated watermark probability `< 0.5`. The watermark estimate is from the LAION-5B metadata, the aesthetics score is estimated using an [improved aesthetics estimator](https://github.com/christophschuhmann/improved-aesthetic-predictor)).
|
148 |
+
- `sd-v1-3.ckpt`: Resumed from `sd-v1-2.ckpt`. 195k steps at resolution `512x512` on "laion-improved-aesthetics" and 10\% dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598).
|
149 |
+
|
150 |
+
|
151 |
+
- **Hardware:** 32 x 8 x A100 GPUs
|
152 |
+
- **Optimizer:** AdamW
|
153 |
+
- **Gradient Accumulations**: 2
|
154 |
+
- **Batch:** 32 x 8 x 2 x 4 = 2048
|
155 |
+
- **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
|
156 |
+
|
157 |
+
## Evaluation Results
|
158 |
+
Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
|
159 |
+
5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling
|
160 |
+
steps show the relative improvements of the checkpoints:
|
161 |
+
|
162 |
+
![pareto](v1-variants-scores.jpg)
|
163 |
+
|
164 |
+
Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
|
165 |
+
## Environmental Impact
|
166 |
+
|
167 |
+
**Stable Diffusion v1** **Estimated Emissions**
|
168 |
+
Based on that information, we estimate the following CO2 emissions using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700). The hardware, runtime, cloud provider, and compute region were utilized to estimate the carbon impact.
|
169 |
+
|
170 |
+
- **Hardware Type:** A100 PCIe 40GB
|
171 |
+
- **Hours used:** 150000
|
172 |
+
- **Cloud Provider:** AWS
|
173 |
+
- **Compute Region:** US-east
|
174 |
+
- **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.
|
175 |
+
|
176 |
+
## Usage
|
177 |
+
|
178 |
+
### Setup
|
179 |
+
|
180 |
+
- Install `diffusers` with
|
181 |
+
|
182 |
+
`pip install -U git+https://github.com/huggingface/diffusers.git`
|
183 |
+
- Install `transformers` with
|
184 |
+
|
185 |
+
`pip install transformers`
|
186 |
+
|
187 |
+
```python
|
188 |
+
import torch
|
189 |
+
from diffusers import StableDiffusionPipeline
|
190 |
+
|
191 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-2-diffusers")
|
192 |
+
|
193 |
+
prompt = "19th Century wooden engraving of Elon musk"
|
194 |
+
|
195 |
+
seed = torch.manual_seed(1024)
|
196 |
+
images = pipe([prompt], num_inference_steps=50, guidance_scale=7.5, generator=seed)["sample"]
|
197 |
+
|
198 |
+
# save images
|
199 |
+
for idx, image in enumerate(images):
|
200 |
+
image.save(f"image-{idx}.png")
|
201 |
+
```
|
202 |
+
|
203 |
+
|
204 |
+
## Citation
|
205 |
+
|
206 |
+
```bibtex
|
207 |
+
@InProceedings{Rombach_2022_CVPR,
|
208 |
+
author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
|
209 |
+
title = {High-Resolution Image Synthesis With Latent Diffusion Models},
|
210 |
+
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
211 |
+
month = {June},
|
212 |
+
year = {2022},
|
213 |
+
pages = {10684-10695}
|
214 |
+
}
|
215 |
+
```
|
216 |
+
|
217 |
+
*This model card was written by: Robin Rombach and Patrick Esser and is based on the [DALL-E Mini model card](https://huggingface.co/dalle-mini/dalle-mini).*
|