CoolFace
Modelpublic

embedingHF/stable-diffusion-v1-5

sourceHugging Facecreativeml-openrail-mupdated 2mo agoView on Hugging Face
0likes29downloads
README.md202 linesDownload Raw Back to root
1---2license: creativeml-openrail-m3tags:4- stable-diffusion5- stable-diffusion-diffusers6- text-to-image7inference: true8---9 10# Stable Diffusion v1-5 Model Card11 12### ⚠️ This repository is a mirror of the now deprecated `ruwnayml/stable-diffusion-v1-5`, this repository or organization are not affiliated in any way with RunwayML.13Modifications to the original model card are in <span style="color:crimson">red</span> or <span style="color:darkgreen">green</span>14 15Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.16For more information about how Stable Diffusion functions, please have a look at [🤗's Stable Diffusion blog](https://huggingface.co/blog/stable_diffusion).17 18The **Stable-Diffusion-v1-5** checkpoint was initialized with the weights of the [Stable-Diffusion-v1-2](https:/steps/huggingface.co/CompVis/stable-diffusion-v1-2) 19checkpoint and subsequently fine-tuned on 595k 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).20 21You can use this both with the [🧨Diffusers library](https://github.com/huggingface/diffusers) and [RunwayML GitHub repository](https://github.com/runwayml/stable-diffusion) (<span style="color:crimson">now deprecated</span>), <span style="color:darkgreen">ComfyUI, Automatic1111, SD.Next, InvokeAI</span>.22 23### Use with Diffusers24```py25from diffusers import StableDiffusionPipeline26import torch27 28model_id = "sd-legacy/stable-diffusion-v1-5"29pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)30pipe = pipe.to("cuda")31 32prompt = "a photo of an astronaut riding a horse on mars"33image = pipe(prompt).images[0]  34    35image.save("astronaut_rides_horse.png")36```37For more detailed instructions, use-cases and examples in JAX follow the instructions [here](https://github.com/huggingface/diffusers#text-to-image-generation-with-stable-diffusion)38 39### Use with GitHub Repository <span style="color:crimson">(now deprecated)</span>, <span style="color:darkgreen">ComfyUI or Automatic1111</span>40 411. Download the weights 42   - [v1-5-pruned-emaonly.safetensors](https://huggingface.co/sd-legacy/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors) - ema-only weight. uses less VRAM - suitable for inference43   - [v1-5-pruned.safetensors](https://huggingface.co/sd-legacy/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors) - ema+non-ema weights. uses more VRAM - suitable for fine-tuning44 452. Follow instructions [here](https://github.com/runwayml/stable-diffusion). <span style="color:crimson">(now deprecated)</span>46 473. <span style="color:darkgreen">Use locally with <a href="https://github.com/comfyanonymous/ComfyUI">ComfyUI</a>, <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui">AUTOMATIC1111</a>, <a href="https://github.com/vladmandic/automatic">SD.Next</a>, <a href="https://github.com/invoke-ai/InvokeAI">InvokeAI</a></span>48 49## Model Details50- **Developed by:** Robin Rombach, Patrick Esser51- **Model type:** Diffusion-based text-to-image generation model52- **Language(s):** English53- **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.54- **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).55- **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).56- **Cite as:**57 58      @InProceedings{Rombach_2022_CVPR,59          author    = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},60          title     = {High-Resolution Image Synthesis With Latent Diffusion Models},61          booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},62          month     = {June},63          year      = {2022},64          pages     = {10684-10695}65      }66 67# Uses68 69## Direct Use 70The model is intended for research purposes only. Possible research areas and71tasks include72 73- Safe deployment of models which have the potential to generate harmful content.74- Probing and understanding the limitations and biases of generative models.75- Generation of artworks and use in design and other artistic processes.76- Applications in educational or creative tools.77- Research on generative models.78 79Excluded uses are described below.80 81 ### Misuse, Malicious Use, and Out-of-Scope Use82_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_.83 84 85The 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.86 87#### Out-of-Scope Use88The 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 90#### Misuse and Malicious Use91Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:92 93- Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.94- Intentionally promoting or propagating discriminatory content or harmful stereotypes.95- Impersonating individuals without their consent.96- Sexual content without consent of the people who might see it.97- Mis- and disinformation98- Representations of egregious violence and gore99- Sharing of copyrighted or licensed material in violation of its terms of use.100- Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.101 102## Limitations and Bias103 104### Limitations105 106- The model does not achieve perfect photorealism107- The model cannot render legible text108- 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”109- Faces and people in general may not be generated properly.110- The model was trained mainly with English captions and will not work as well in other languages.111- The autoencoding part of the model is lossy112- The model was trained on a large-scale dataset113  [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material114  and is not fit for product use without additional safety mechanisms and115  considerations.116- 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.117  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.118 119### Bias120 121While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases. 122Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/), 123which consists of images that are primarily limited to English descriptions. 124Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for. 125This affects the overall output of the model, as white and western cultures are often set as the default. Further, the 126ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.127 128### Safety Module129 130The 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. 131This checker works by checking model outputs against known hard-coded NSFW concepts.132The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter.133Specifically, the checker compares the class probability of harmful concepts in the embedding space of the `CLIPTextModel` *after generation* of the images. 134The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.135 136 137## Training138 139**Training Data**140The model developers used the following dataset for training the model:141 142- LAION-2B (en) and subsets thereof (see next section)143 144**Training Procedure**145Stable Diffusion v1-5 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, 146 147- 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 4148- Text prompts are encoded through a ViT-L/14 text-encoder.149- The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.150- The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.151 152Currently six Stable Diffusion checkpoints are provided, which were trained as follows.153- [`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).154  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`).155- [`stable-diffusion-v1-2`](https://huggingface.co/CompVis/stable-diffusion-v1-2): Resumed from `stable-diffusion-v1-1`.156  515,000 steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,157filtered 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)).158- [`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).159- [`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).160- [`stable-diffusion-v1-5`](https://huggingface.co/sd-legacy/stable-diffusion-v1-5) Resumed from `stable-diffusion-v1-2` - 595,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).161- [`stable-diffusion-inpainting`](https://huggingface.co/sd-legacy/stable-diffusion-inpainting) Resumed from `stable-diffusion-v1-5` - then 440,000 steps of inpainting training at resolution 512x512 on “laion-aesthetics v2 5+” and 10% dropping of the text-conditioning. For inpainting, the UNet has 5 additional input channels (4 for the encoded masked-image and 1 for the mask itself) whose weights were zero-initialized after restoring the non-inpainting checkpoint. During training, we generate synthetic masks and in 25% mask everything.162 163- **Hardware:** 32 x 8 x A100 GPUs164- **Optimizer:** AdamW165- **Gradient Accumulations**: 2166- **Batch:** 32 x 8 x 2 x 4 = 2048167- **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant168 169## Evaluation Results 170Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,1715.0, 6.0, 7.0, 8.0) and 50 PNDM/PLMS sampling172steps show the relative improvements of the checkpoints:173 174![pareto](https://huggingface.co/CompVis/stable-diffusion/resolve/main/v1-1-to-v1-5.png)175 176Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution.  Not optimized for FID scores.177## Environmental Impact178 179**Stable Diffusion v1** **Estimated Emissions**180Based 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.181 182- **Hardware Type:** A100 PCIe 40GB183- **Hours used:** 150000184- **Cloud Provider:** AWS185- **Compute Region:** US-east186- **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.187 188 189## Citation190 191```bibtex192    @InProceedings{Rombach_2022_CVPR,193        author    = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},194        title     = {High-Resolution Image Synthesis With Latent Diffusion Models},195        booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},196        month     = {June},197        year      = {2022},198        pages     = {10684-10695}199    }200```201 202*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).*