Update README.md

#151
by Jannat - opened
Files changed (1) hide show
  1. README.md +1 -330
README.md CHANGED
@@ -1,330 +1 @@
1
- ---
2
- license: creativeml-openrail-m
3
- tags:
4
- - stable-diffusion
5
- - stable-diffusion-diffusers
6
- - text-to-image
7
- widget:
8
- - text: "A high tech solarpunk utopia in the Amazon rainforest"
9
- example_title: Amazon rainforest
10
- - text: "A pikachu fine dining with a view to the Eiffel Tower"
11
- example_title: Pikachu in Paris
12
- - text: "A mecha robot in a favela in expressionist style"
13
- example_title: Expressionist robot
14
- - text: "an insect robot preparing a delicious meal"
15
- example_title: Insect robot
16
- - text: "A small cabin on top of a snowy mountain in the style of Disney, artstation"
17
- example_title: Snowy disney cabin
18
- extra_gated_prompt: |-
19
- This model is open access and available to all, with a CreativeML OpenRAIL-M license further specifying rights and usage.
20
- The CreativeML OpenRAIL License specifies:
21
-
22
- 1. You can't use the model to deliberately produce nor share illegal or harmful outputs or content
23
- 2. The authors claim 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
24
- 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)
25
- Please read the full license carefully here: https://huggingface.co/spaces/CompVis/stable-diffusion-license
26
-
27
- extra_gated_heading: Please read the LICENSE to access this model
28
- ---
29
-
30
- # Stable Diffusion v1-4 Model Card
31
-
32
- Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
33
- 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).
34
-
35
- 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)
36
- 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).
37
-
38
- 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)
39
-
40
- ## Model Details
41
- - **Developed by:** Robin Rombach, Patrick Esser
42
- - **Model type:** Diffusion-based text-to-image generation model
43
- - **Language(s):** English
44
- - **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.
45
- - **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).
46
- - **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).
47
- - **Cite as:**
48
-
49
- @InProceedings{Rombach_2022_CVPR,
50
- author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
51
- title = {High-Resolution Image Synthesis With Latent Diffusion Models},
52
- booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
53
- month = {June},
54
- year = {2022},
55
- pages = {10684-10695}
56
- }
57
-
58
- ## Examples
59
-
60
- We recommend using [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion.
61
-
62
- ### PyTorch
63
-
64
- ```bash
65
- pip install --upgrade diffusers transformers scipy
66
- ```
67
-
68
- Run this command to log in with your HF Hub token if you haven't before:
69
-
70
- ```bash
71
- huggingface-cli login
72
- ```
73
-
74
- Running the pipeline with the default PNDM scheduler:
75
-
76
- ```python
77
- import torch
78
- from diffusers import StableDiffusionPipeline
79
-
80
- model_id = "CompVis/stable-diffusion-v1-4"
81
- device = "cuda"
82
-
83
-
84
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")
85
- pipe = pipe.to(device)
86
-
87
- prompt = "a photo of an astronaut riding a horse on mars"
88
- image = pipe(prompt).images[0]
89
-
90
- image.save("astronaut_rides_horse.png")
91
- ```
92
-
93
- **Note**:
94
- If you are limited by GPU memory and have less than 4GB 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:
95
-
96
-
97
- ```py
98
- import torch
99
-
100
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")
101
- pipe = pipe.to(device)
102
- pipe.enable_attention_slicing()
103
-
104
- prompt = "a photo of an astronaut riding a horse on mars"
105
- image = pipe(prompt).images[0]
106
-
107
- image.save("astronaut_rides_horse.png")
108
- ```
109
-
110
- To swap out the noise scheduler, pass it to `from_pretrained`:
111
-
112
- ```python
113
- from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
114
-
115
- model_id = "CompVis/stable-diffusion-v1-4"
116
-
117
- # Use the Euler scheduler here instead
118
- scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
119
- pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16, revision="fp16")
120
- pipe = pipe.to("cuda")
121
-
122
- prompt = "a photo of an astronaut riding a horse on mars"
123
- image = pipe(prompt).images[0]
124
-
125
- image.save("astronaut_rides_horse.png")
126
- ```
127
-
128
- ### JAX/Flax
129
-
130
- To use StableDiffusion on TPUs and GPUs for faster inference you can leverage JAX/Flax.
131
-
132
- Running the pipeline with default PNDMScheduler
133
-
134
- ```python
135
- import jax
136
- import numpy as np
137
- from flax.jax_utils import replicate
138
- from flax.training.common_utils import shard
139
-
140
- from diffusers import FlaxStableDiffusionPipeline
141
-
142
- pipeline, params = FlaxStableDiffusionPipeline.from_pretrained(
143
- "CompVis/stable-diffusion-v1-4", revision="flax", dtype=jax.numpy.bfloat16
144
- )
145
-
146
- prompt = "a photo of an astronaut riding a horse on mars"
147
-
148
- prng_seed = jax.random.PRNGKey(0)
149
- num_inference_steps = 50
150
-
151
- num_samples = jax.device_count()
152
- prompt = num_samples * [prompt]
153
- prompt_ids = pipeline.prepare_inputs(prompt)
154
-
155
- # shard inputs and rng
156
- params = replicate(params)
157
- prng_seed = jax.random.split(prng_seed, 8)
158
- prompt_ids = shard(prompt_ids)
159
-
160
- images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images
161
- images = pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
162
- ```
163
-
164
- **Note**:
165
- If you are limited by TPU memory, please make sure to load the `FlaxStableDiffusionPipeline` in `bfloat16` precision instead of the default `float32` precision as done above. You can do so by telling diffusers to load the weights from "bf16" branch.
166
-
167
- ```python
168
- import jax
169
- import numpy as np
170
- from flax.jax_utils import replicate
171
- from flax.training.common_utils import shard
172
-
173
- from diffusers import FlaxStableDiffusionPipeline
174
-
175
- pipeline, params = FlaxStableDiffusionPipeline.from_pretrained(
176
- "CompVis/stable-diffusion-v1-4", revision="bf16", dtype=jax.numpy.bfloat16
177
- )
178
-
179
- prompt = "a photo of an astronaut riding a horse on mars"
180
-
181
- prng_seed = jax.random.PRNGKey(0)
182
- num_inference_steps = 50
183
-
184
- num_samples = jax.device_count()
185
- prompt = num_samples * [prompt]
186
- prompt_ids = pipeline.prepare_inputs(prompt)
187
-
188
- # shard inputs and rng
189
- params = replicate(params)
190
- prng_seed = jax.random.split(prng_seed, 8)
191
- prompt_ids = shard(prompt_ids)
192
-
193
- images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images
194
- images = pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
195
- ```
196
-
197
- # Uses
198
-
199
- ## Direct Use
200
- The model is intended for research purposes only. Possible research areas and
201
- tasks include
202
-
203
- - Safe deployment of models which have the potential to generate harmful content.
204
- - Probing and understanding the limitations and biases of generative models.
205
- - Generation of artworks and use in design and other artistic processes.
206
- - Applications in educational or creative tools.
207
- - Research on generative models.
208
-
209
- Excluded uses are described below.
210
-
211
- ### Misuse, Malicious Use, and Out-of-Scope Use
212
- _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_.
213
-
214
-
215
- 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.
216
-
217
- #### Out-of-Scope Use
218
- 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.
219
-
220
- #### Misuse and Malicious Use
221
- Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
222
-
223
- - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
224
- - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
225
- - Impersonating individuals without their consent.
226
- - Sexual content without consent of the people who might see it.
227
- - Mis- and disinformation
228
- - Representations of egregious violence and gore
229
- - Sharing of copyrighted or licensed material in violation of its terms of use.
230
- - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
231
-
232
- ## Limitations and Bias
233
-
234
- ### Limitations
235
-
236
- - The model does not achieve perfect photorealism
237
- - The model cannot render legible text
238
- - 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”
239
- - Faces and people in general may not be generated properly.
240
- - The model was trained mainly with English captions and will not work as well in other languages.
241
- - The autoencoding part of the model is lossy
242
- - The model was trained on a large-scale dataset
243
- [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
244
- and is not fit for product use without additional safety mechanisms and
245
- considerations.
246
- - 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.
247
- 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.
248
-
249
- ### Bias
250
-
251
- While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
252
- Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
253
- which consists of images that are primarily limited to English descriptions.
254
- Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
255
- This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
256
- ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
257
-
258
- ### Safety Module
259
-
260
- 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.
261
- This checker works by checking model outputs against known hard-coded NSFW concepts.
262
- The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter.
263
- Specifically, the checker compares the class probability of harmful concepts in the embedding space of the `CLIPTextModel` *after generation* of the images.
264
- The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.
265
-
266
-
267
- ## Training
268
-
269
- **Training Data**
270
- The model developers used the following dataset for training the model:
271
-
272
- - LAION-2B (en) and subsets thereof (see next section)
273
-
274
- **Training Procedure**
275
- 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,
276
-
277
- - 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
278
- - Text prompts are encoded through a ViT-L/14 text-encoder.
279
- - The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
280
- - The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.
281
-
282
- We currently provide four checkpoints, which were trained as follows.
283
- - [`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).
284
- 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`).
285
- - [`stable-diffusion-v1-2`](https://huggingface.co/CompVis/stable-diffusion-v1-2): Resumed from `stable-diffusion-v1-1`.
286
- 515,000 steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,
287
- 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)).
288
- - [`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).
289
- - [`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).
290
-
291
- - **Hardware:** 32 x 8 x A100 GPUs
292
- - **Optimizer:** AdamW
293
- - **Gradient Accumulations**: 2
294
- - **Batch:** 32 x 8 x 2 x 4 = 2048
295
- - **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
296
-
297
- ## Evaluation Results
298
- Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
299
- 5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling
300
- steps show the relative improvements of the checkpoints:
301
-
302
- ![pareto](https://huggingface.co/CompVis/stable-diffusion/resolve/main/v1-variants-scores.jpg)
303
-
304
- Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
305
- ## Environmental Impact
306
-
307
- **Stable Diffusion v1** **Estimated Emissions**
308
- 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.
309
-
310
- - **Hardware Type:** A100 PCIe 40GB
311
- - **Hours used:** 150000
312
- - **Cloud Provider:** AWS
313
- - **Compute Region:** US-east
314
- - **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.
315
-
316
-
317
- ## Citation
318
-
319
- ```bibtex
320
- @InProceedings{Rombach_2022_CVPR,
321
- author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
322
- title = {High-Resolution Image Synthesis With Latent Diffusion Models},
323
- booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
324
- month = {June},
325
- year = {2022},
326
- pages = {10684-10695}
327
- }
328
- ```
329
-
330
- *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).*
 
1
+ Furry fox lies on the bed naked, 18+, porn, naked breasts, 4k