olympictafira commited on
Commit
739e36a
1 Parent(s): 3ee06ac

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +253 -1
README.md CHANGED
@@ -1,3 +1,255 @@
1
  ---
2
- license: afl-3.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: other
3
+ tags:
4
+ - stable-diffusion
5
+ - stable-diffusion-diffusers
6
+ - text-to-image
7
+ inference: false
8
+ extra_gated_prompt: |-
9
+ One more step before getting this model.
10
+ This model is open access and available to all, with a CreativeML OpenRAIL-M license further specifying rights and usage.
11
+ The CreativeML OpenRAIL License specifies:
12
+
13
+ 1. You can't use the model to deliberately produce nor share illegal or harmful outputs or content
14
+ 2. CompVis claims no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in the license
15
+ 3. You may re-distribute the weights and use the model commercially and/or as a service. If you do, please be aware you have to include the same use restrictions as the ones in the license and share a copy of the CreativeML OpenRAIL-M to all your users (please read the license entirely and carefully)
16
+ Please read the full license here: https://huggingface.co/spaces/CompVis/stable-diffusion-license
17
+
18
+ By clicking on "Access repository" below, you accept that your *contact information* (email address and username) can be shared with the model authors as well.
19
+
20
+ extra_gated_fields:
21
+ I have read the License and agree with its terms: checkbox
22
  ---
23
+
24
+ # Stable Diffusion v1-4 Model Card
25
+
26
+ Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
27
+ For more information about how Stable Diffusion functions, please have a look at [🤗's Stable Diffusion with 🧨Diffusers blog](https://huggingface.co/blog/stable_diffusion).
28
+
29
+ The **Stable-Diffusion-v1-4** checkpoint was initialized with the weights of the [Stable-Diffusion-v1-2](https:/steps/huggingface.co/CompVis/stable-diffusion-v1-2)
30
+ checkpoint and subsequently fine-tuned on 225k steps at resolution 512x512 on "laion-aesthetics v2 5+" and 10% dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598).
31
+
32
+ This weights here are intended to be used with the 🧨 Diffusers library. If you are looking for the weights to be loaded into the CompVis Stable Diffusion codebase, [come here](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original)
33
+
34
+ ## Model Details
35
+ - **Developed by:** Robin Rombach, Patrick Esser
36
+ - **Model type:** Diffusion-based text-to-image generation model
37
+ - **Language(s):** English
38
+ - **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.
39
+ - **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).
40
+ - **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).
41
+ - **Cite as:**
42
+
43
+ @InProceedings{Rombach_2022_CVPR,
44
+ author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
45
+ title = {High-Resolution Image Synthesis With Latent Diffusion Models},
46
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
47
+ month = {June},
48
+ year = {2022},
49
+ pages = {10684-10695}
50
+ }
51
+
52
+ ## Examples
53
+
54
+ We recommend using [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion.
55
+
56
+ ```bash
57
+ pip install --upgrade diffusers transformers scipy
58
+ ```
59
+
60
+ Run this command to log in with your HF Hub token if you haven't before:
61
+
62
+ ```bash
63
+ huggingface-cli login
64
+ ```
65
+
66
+ Running the pipeline with the default PNDM scheduler:
67
+
68
+ ```python
69
+ import torch
70
+ from torch import autocast
71
+ from diffusers import StableDiffusionPipeline
72
+
73
+ model_id = "CompVis/stable-diffusion-v1-4"
74
+ device = "cuda"
75
+
76
+
77
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
78
+ pipe = pipe.to(device)
79
+
80
+ prompt = "a photo of an astronaut riding a horse on mars"
81
+ with autocast("cuda"):
82
+ image = pipe(prompt, guidance_scale=7.5).images[0]
83
+
84
+ image.save("astronaut_rides_horse.png")
85
+ ```
86
+
87
+ **Note**:
88
+ If you are limited by GPU memory and have less than 10GB of GPU RAM available, please make sure to load the StableDiffusionPipeline in float16 precision instead of the default float32 precision as done above. You can do so by telling diffusers to expect the weights to be in float16 precision:
89
+
90
+
91
+ ```py
92
+ import torch
93
+
94
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16", use_auth_token=True)
95
+ pipe = pipe.to(device)
96
+
97
+ prompt = "a photo of an astronaut riding a horse on mars"
98
+ with autocast("cuda"):
99
+ image = pipe(prompt, guidance_scale=7.5).images[0]
100
+
101
+ image.save("astronaut_rides_horse.png")
102
+ ```
103
+
104
+ To swap out the noise scheduler, pass it to `from_pretrained`:
105
+
106
+ ```python
107
+ from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
108
+
109
+ model_id = "CompVis/stable-diffusion-v1-4"
110
+ # Use the K-LMS scheduler here instead
111
+ scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
112
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, use_auth_token=True)
113
+ pipe = pipe.to("cuda")
114
+
115
+ prompt = "a photo of an astronaut riding a horse on mars"
116
+ with autocast("cuda"):
117
+ image = pipe(prompt, guidance_scale=7.5).images[0]
118
+
119
+ image.save("astronaut_rides_horse.png")
120
+ ```
121
+
122
+ # Uses
123
+
124
+ ## Direct Use
125
+ The model is intended for research purposes only. Possible research areas and
126
+ tasks include
127
+
128
+ - Safe deployment of models which have the potential to generate harmful content.
129
+ - Probing and understanding the limitations and biases of generative models.
130
+ - Generation of artworks and use in design and other artistic processes.
131
+ - Applications in educational or creative tools.
132
+ - Research on generative models.
133
+
134
+ Excluded uses are described below.
135
+
136
+ ### Misuse, Malicious Use, and Out-of-Scope Use
137
+ _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_.
138
+
139
+
140
+ 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.
141
+
142
+ #### Out-of-Scope Use
143
+ 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.
144
+
145
+ #### Misuse and Malicious Use
146
+ Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
147
+
148
+ - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
149
+ - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
150
+ - Impersonating individuals without their consent.
151
+ - Sexual content without consent of the people who might see it.
152
+ - Mis- and disinformation
153
+ - Representations of egregious violence and gore
154
+ - Sharing of copyrighted or licensed material in violation of its terms of use.
155
+ - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
156
+
157
+ ## Limitations and Bias
158
+
159
+ ### Limitations
160
+
161
+ - The model does not achieve perfect photorealism
162
+ - The model cannot render legible text
163
+ - 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”
164
+ - Faces and people in general may not be generated properly.
165
+ - The model was trained mainly with English captions and will not work as well in other languages.
166
+ - The autoencoding part of the model is lossy
167
+ - The model was trained on a large-scale dataset
168
+ [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
169
+ and is not fit for product use without additional safety mechanisms and
170
+ considerations.
171
+ - No additional measures were used to deduplicate the dataset. As a result, we observe some degree of memorization for images that are duplicated in the training data.
172
+ The training data can be searched at [https://rom1504.github.io/clip-retrieval/](https://rom1504.github.io/clip-retrieval/) to possibly assist in the detection of memorized images.
173
+
174
+ ### Bias
175
+
176
+ While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
177
+ Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
178
+ which consists of images that are primarily limited to English descriptions.
179
+ Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
180
+ This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
181
+ ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
182
+
183
+ ### Safety Module
184
+
185
+ The intended use of this model is with the [Safety Checker](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/safety_checker.py) in Diffusers.
186
+ This checker works by checking model outputs against known hard-coded NSFW concepts.
187
+ The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter.
188
+ Specifically, the checker compares the class probability of harmful concepts in the embedding space of the `CLIPTextModel` *after generation* of the images.
189
+ The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.
190
+
191
+
192
+ ## Training
193
+
194
+ **Training Data**
195
+ The model developers used the following dataset for training the model:
196
+
197
+ - LAION-2B (en) and subsets thereof (see next section)
198
+
199
+ **Training Procedure**
200
+ Stable Diffusion v1-4 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,
201
+
202
+ - 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
203
+ - Text prompts are encoded through a ViT-L/14 text-encoder.
204
+ - The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
205
+ - The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.
206
+
207
+ We currently provide four checkpoints, which were trained as follows.
208
+ - [`stable-diffusion-v1-1`](https://huggingface.co/CompVis/stable-diffusion-v1-1): 237,000 steps at resolution `256x256` on [laion2B-en](https://huggingface.co/datasets/laion/laion2B-en).
209
+ 194,000 steps at resolution `512x512` on [laion-high-resolution](https://huggingface.co/datasets/laion/laion-high-resolution) (170M examples from LAION-5B with resolution `>= 1024x1024`).
210
+ - [`stable-diffusion-v1-2`](https://huggingface.co/CompVis/stable-diffusion-v1-2): Resumed from `stable-diffusion-v1-1`.
211
+ 515,000 steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,
212
+ 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)).
213
+ - [`stable-diffusion-v1-3`](https://huggingface.co/CompVis/stable-diffusion-v1-3): Resumed from `stable-diffusion-v1-2`. 195,000 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).
214
+ - [`stable-diffusion-v1-4`](https://huggingface.co/CompVis/stable-diffusion-v1-4) Resumed from `stable-diffusion-v1-2`.225,000 steps at resolution `512x512` on "laion-aesthetics v2 5+" and 10 % dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598).
215
+
216
+ - **Hardware:** 32 x 8 x A100 GPUs
217
+ - **Optimizer:** AdamW
218
+ - **Gradient Accumulations**: 2
219
+ - **Batch:** 32 x 8 x 2 x 4 = 2048
220
+ - **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
221
+
222
+ ## Evaluation Results
223
+ Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
224
+ 5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling
225
+ steps show the relative improvements of the checkpoints:
226
+
227
+ ![pareto](https://huggingface.co/CompVis/stable-diffusion/resolve/main/v1-variants-scores.jpg)
228
+
229
+ Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
230
+ ## Environmental Impact
231
+
232
+ **Stable Diffusion v1** **Estimated Emissions**
233
+ 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.
234
+
235
+ - **Hardware Type:** A100 PCIe 40GB
236
+ - **Hours used:** 150000
237
+ - **Cloud Provider:** AWS
238
+ - **Compute Region:** US-east
239
+ - **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.
240
+
241
+
242
+ ## Citation
243
+
244
+ ```bibtex
245
+ @InProceedings{Rombach_2022_CVPR,
246
+ author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
247
+ title = {High-Resolution Image Synthesis With Latent Diffusion Models},
248
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
249
+ month = {June},
250
+ year = {2022},
251
+ pages = {10684-10695}
252
+ }
253
+ ```
254
+
255
+ *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).*://huggingface.co/CompVis/stable-diffusion-v1-4