https://github.com/compvis/stable-diffusion

A latent text-to-image diffusion model

https://github.com/compvis/stable-diffusion

Science Score: 33.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
    2 of 8 committers (25.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.1%) to scientific vocabulary

Keywords from Contributors

diffusion image-generation image2image stable-diffusion text2image flux image2video latent-diffusion-models qwen-image score-based-generative-modeling
Last synced: 10 months ago · JSON representation

Repository

A latent text-to-image diffusion model

Basic Info
Statistics
  • Stars: 70,677
  • Watchers: 574
  • Forks: 10,441
  • Open Issues: 604
  • Releases: 0
Created almost 4 years ago · Last pushed about 2 years ago
Metadata Files
Readme License

README.md

Stable Diffusion

Stable Diffusion was made possible thanks to a collaboration with Stability AI and Runway and builds upon our previous work:

High-Resolution Image Synthesis with Latent Diffusion Models
Robin Rombach*, Andreas Blattmann*, Dominik Lorenz\, Patrick Esser, Björn Ommer
[CVPR '22 Oral](https://openaccess.thecvf.com/content/CVPR2022/html/RombachHigh-ResolutionImageSynthesisWithLatentDiffusionModelsCVPR2022paper.html) | GitHub | arXiv | Project page

txt2img-stable2 Stable Diffusion is a latent text-to-image diffusion model. Thanks to a generous compute donation from Stability AI and support from LAION, we were able to train a Latent Diffusion Model on 512x512 images from a subset of the LAION-5B database. Similar to Google's Imagen, this model uses a frozen CLIP ViT-L/14 text encoder to condition the model on text prompts. With its 860M UNet and 123M text encoder, the model is relatively lightweight and runs on a GPU with at least 10GB VRAM. See this section below and the model card.

Requirements

A suitable conda environment named ldm can be created and activated with:

conda env create -f environment.yaml conda activate ldm

You can also update an existing latent diffusion environment by running

conda install pytorch torchvision -c pytorch pip install transformers==4.19.2 diffusers invisible-watermark pip install -e .

Stable Diffusion v1

Stable Diffusion v1 refers to a specific configuration of the model architecture that uses a downsampling-factor 8 autoencoder with an 860M UNet and CLIP ViT-L/14 text encoder for the diffusion model. The model was pretrained on 256x256 images and then finetuned on 512x512 images.

Note: Stable Diffusion v1 is a general text-to-image diffusion model and therefore mirrors biases and (mis-)conceptions that are present in its training data. Details on the training procedure and data, as well as the intended use of the model can be found in the corresponding model card.

The weights are available via the CompVis organization at Hugging Face under a license which contains specific use-based restrictions to prevent misuse and harm as informed by the model card, but otherwise remains permissive. While commercial use is permitted under the terms of the license, we do not recommend using the provided weights for services or products without additional safety mechanisms and considerations, since there are known limitations and biases of the weights, and research on safe and ethical deployment of general text-to-image models is an ongoing effort. The weights are research artifacts and should be treated as such.

The CreativeML OpenRAIL M license is an Open RAIL M license, adapted from the work that BigScience and the RAIL Initiative are jointly carrying in the area of responsible AI licensing. See also the article about the BLOOM Open RAIL license on which our license is based.

Weights

We currently provide the following checkpoints:

  • sd-v1-1.ckpt: 237k steps at resolution 256x256 on laion2B-en. 194k steps at resolution 512x512 on laion-high-resolution (170M examples from LAION-5B with resolution >= 1024x1024).
  • sd-v1-2.ckpt: Resumed from sd-v1-1.ckpt. 515k steps at resolution 512x512 on laion-aesthetics v2 5+ (a subset of laion2B-en with estimated aesthetics score > 5.0, and additionally filtered to images with an original size >= 512x512, and an estimated watermark probability < 0.5. The watermark estimate is from the LAION-5B metadata, the aesthetics score is estimated using the LAION-Aesthetics Predictor V2).
  • sd-v1-3.ckpt: Resumed from sd-v1-2.ckpt. 195k steps at resolution 512x512 on "laion-aesthetics v2 5+" and 10\% dropping of the text-conditioning to improve classifier-free guidance sampling.
  • sd-v1-4.ckpt: Resumed from sd-v1-2.ckpt. 225k steps at resolution 512x512 on "laion-aesthetics v2 5+" and 10\% dropping of the text-conditioning to improve classifier-free guidance sampling.

Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling steps show the relative improvements of the checkpoints: sd evaluation results

Text-to-Image with Stable Diffusion

txt2img-stable2 txt2img-stable2

Stable Diffusion is a latent diffusion model conditioned on the (non-pooled) text embeddings of a CLIP ViT-L/14 text encoder. We provide a reference script for sampling, but there also exists a diffusers integration, which we expect to see more active community development.

Reference Sampling Script

We provide a reference sampling script, which incorporates

After obtaining the stable-diffusion-v1-*-original weights, link them mkdir -p models/ldm/stable-diffusion-v1/ ln -s <path/to/model.ckpt> models/ldm/stable-diffusion-v1/model.ckpt and sample with python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms

By default, this uses a guidance scale of --scale 7.5, Katherine Crowson's implementation of the PLMS sampler, and renders images of size 512x512 (which it was trained on) in 50 steps. All supported arguments are listed below (type python scripts/txt2img.py --help).

```commandline usage: txt2img.py [-h] [--prompt [PROMPT]] [--outdir [OUTDIR]] [--skip_grid] [--skip_save] [--ddimsteps DDIMSTEPS] [--plms] [--laion400m] [--fixed_code] [--ddimeta DDIMETA] [--niter NITER] [--H H] [--W W] [--C C] [--f F] [--nsamples NSAMPLES] [--nrows NROWS] [--scale SCALE] [--from-file FROM_FILE] [--config CONFIG] [--ckpt CKPT] [--seed SEED] [--precision {full,autocast}]

optional arguments: -h, --help show this help message and exit --prompt [PROMPT] the prompt to render --outdir [OUTDIR] dir to write results to --skipgrid do not save a grid, only individual samples. Helpful when evaluating lots of samples --skipsave do not save individual samples. For speed measurements. --ddimsteps DDIMSTEPS number of ddim sampling steps --plms use plms sampling --laion400m uses the LAION400M model --fixedcode if enabled, uses the same starting code across samples --ddimeta DDIMETA ddim eta (eta=0.0 corresponds to deterministic sampling --niter NITER sample this often --H H image height, in pixel space --W W image width, in pixel space --C C latent channels --f F downsampling factor --nsamples NSAMPLES how many samples to produce for each given prompt. A.k.a. batch size --nrows NROWS rows in the grid (default: nsamples) --scale SCALE unconditional guidance scale: eps = eps(x, empty) + scale * (eps(x, cond) - eps(x, empty)) --from-file FROMFILE if specified, load prompts from this file --config CONFIG path to config which constructs model --ckpt CKPT path to checkpoint of model --seed SEED the seed (for reproducible sampling) --precision {full,autocast} evaluate at this precision `` Note: The inference config for all v1 versions is designed to be used with EMA-only checkpoints. For this reasonuseema=Falseis set in the configuration, otherwise the code will try to switch from non-EMA to EMA weights. If you want to examine the effect of EMA vs no EMA, we provide "full" checkpoints which contain both types of weights. For these,use_ema=False` will load and use the non-EMA weights.

Diffusers Integration

A simple way to download and sample Stable Diffusion is by using the diffusers library: ```py

make sure you're logged in with huggingface-cli login

from torch import autocast from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.frompretrained( "CompVis/stable-diffusion-v1-4", useauth_token=True ).to("cuda")

prompt = "a photo of an astronaut riding a horse on mars" with autocast("cuda"): image = pipe(prompt)["sample"][0]

image.save("astronautrideshorse.png") ```

Image Modification with Stable Diffusion

By using a diffusion-denoising mechanism as first proposed by SDEdit, the model can be used for different tasks such as text-guided image-to-image translation and upscaling. Similar to the txt2img sampling script, we provide a script to perform image modification with Stable Diffusion.

The following describes an example where a rough sketch made in Pinta is converted into a detailed artwork. python scripts/img2img.py --prompt "A fantasy landscape, trending on artstation" --init-img <path-to-img.jpg> --strength 0.8 Here, strength is a value between 0.0 and 1.0, that controls the amount of noise that is added to the input image. Values that approach 1.0 allow for lots of variations but will also produce images that are not semantically consistent with the input. See the following example.

Input

sketch-in

Outputs

out3 out2

This procedure can, for example, also be used to upscale samples from the base model.

Comments

BibTeX

@misc{rombach2021highresolution, title={High-Resolution Image Synthesis with Latent Diffusion Models}, author={Robin Rombach and Andreas Blattmann and Dominik Lorenz and Patrick Esser and Björn Ommer}, year={2021}, eprint={2112.10752}, archivePrefix={arXiv}, primaryClass={cs.CV} }

Owner

  • Name: CompVis - Computer Vision and Learning LMU Munich
  • Login: CompVis
  • Kind: organization
  • Email: assist.mvl@lrz.uni-muenchen.de
  • Location: Germany

Computer Vision and Learning research group at Ludwig Maximilian University of Munich (formerly Computer Vision Group at Heidelberg University)

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 27
  • Total Committers: 8
  • Avg Commits per committer: 3.375
  • Development Distribution Score (DDS): 0.741
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Robin Rombach r****h@g****m 7
Patrick von Platen p****n@g****m 5
ablattmann a****n@i****e 5
Patrick Esser p****r@g****t 4
owenvincent 7****t 2
LuChengTHU l****5@g****m 2
cpacker c****r@b****u 1
apolinario j****s@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 183
  • Total pull requests: 43
  • Average time to close issues: 4 months
  • Average time to close pull requests: 3 months
  • Total issue authors: 173
  • Total pull request authors: 32
  • Average comments per issue: 8.79
  • Average comments per pull request: 1.65
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 16
  • Pull requests: 16
  • Average time to close issues: 6 days
  • Average time to close pull requests: about 12 hours
  • Issue authors: 16
  • Pull request authors: 7
  • Average comments per issue: 0.94
  • Average comments per pull request: 0.19
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • TkonstAL (3)
  • MojoJojo43 (2)
  • mamalieaz (2)
  • betterze (2)
  • RedEagleP1 (2)
  • Zondakage (2)
  • alphacoder01 (2)
  • ikarth (2)
  • LucasSilvaFerreira (2)
  • sparta218 (2)
  • 2blackbar (1)
  • woonwoon (1)
  • Jusi468899 (1)
  • marctimjen (1)
  • zesameri (1)
Pull Request Authors
  • Rganeshk (6)
  • connie-m-hickson (3)
  • nonetrix (2)
  • Rmattmann501 (2)
  • WZMIAOMIAO (2)
  • houssem-troudi-dev (2)
  • Giorgos008 (2)
  • aizausman (2)
  • BIG-cboy (2)
  • Esmail-ibraheem (2)
  • sozmedya27 (2)
  • arcanite24 (2)
  • xaroth8088 (2)
  • silky1708 (2)
  • Lex-DRL (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 12
  • Total downloads: unknown
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 12
pypi.org: fsfsdfsfs

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: cccccvvvvvvvvvvv

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: kgop

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: trtrtrtrtrtrtrtrtrooo

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: fjdknlsfjkdslfjdso

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: ppppppppppppp

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: jfdklsfslfjskfjkslfjsdl

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: test1011

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: vjkldfgjdfklgjdflkgjdl

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: jgkdlsjgopsdjgsdog

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: kldpapapapa

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: over 1 year ago
pypi.org: trytest101

This package is used for security research and demonstrations. It might contain dangerous code snippets. Do not run.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 0.0%
Forks count: 0.1%
Average: 2.8%
Dependent packages count: 4.8%
Dependent repos count: 6.3%
Last synced: 10 months ago

Dependencies

setup.py pypi
  • numpy *
  • torch *
  • tqdm *
environment.yaml conda
  • cudatoolkit 11.3.*
  • numpy 1.19.2.*
  • pip 20.3.*
  • python 3.8.5.*
  • pytorch 1.11.0.*
  • torchvision 0.12.0.*