Camilo Carvajal Reyes
Supervised by Felipe Tobar and Joaquín Fontbona
Work in progress. This README has certain parts of the original stable diffusion project, but it emphasises the changes we have made.
A suitable conda environment named ldm can be created
and activated with:
conda env create -f environment.yaml
conda activate ldm
After obtaining the CompVis stable-diffusion-v1-4-original weights, download them and put them on the following (new) directory:
mkdir -p models/ldm/stable-diffusion-v1/
and sample with
python scripts/txt2img.py --ckpt models/ldm/stable-diffusion-v1/sd-v1-4.ckpt --prompt "your mom is so fat... " --ddim_steps 50 --clf "CLIP_cosine" --gamma 75 --eta 0.23 --concept "violence,nudity,NSFW,harmful" --n_samples 2 --n_iter 2 --seed 42
The example below produces images shown after the parameters table (it does not use classifier unguidance yet). All supported arguments are listed below (type python scripts/txt2img.py --help).
usage: txt2img.py [-h] [--prompt [PROMPT]] [--outdir [OUTDIR]] [--skip_grid] [--skip_save] [--ddim_steps DDIM_STEPS] [--plms] [--laion400m] [--fixed_code] [--ddim_eta DDIM_ETA]
[--n_iter N_ITER] [--H H] [--W W] [--C C] [--f F] [--n_samples N_SAMPLES] [--n_rows N_ROWS] [--scale SCALE] [--from-file FROM_FILE] [--config CONFIG] [--ckpt CKPT]
[--seed SEED] [--precision {full,autocast}] [--gamma GAMMA] [--clf {CLIP_cosine,CLIP_matching,ALIGN_matching,None}]
[--concept CONCEPT] [--top_k TOP_K] [--eta ETA]
added arguments:
--gamma GAMMA Unguidance strength (Guidance factor in Universal Guidance)
--clf {CLIP_cosine,CLIP_matching,ALIGN_matching,None}
classifier for unguidance, 'None' for no unguidance
--concept CONCEPT Concepts to include in CLIP/ALIGN guidance signals, comma-separated
--top_k TOP_K Only highest top_k probabilities will be considered (applicable to
multiconcept CLFs)
--eta ETA threshold for applying the classifier unguidance. If the probability is under
the threshold, the noise network remains unchanged.
optional arguments:
-h, --help show this help message and exit
--prompt [PROMPT] the prompt to render
--outdir [OUTDIR] dir to write results to
--skip_grid do not save a grid, only individual samples. Helpful when evaluating lots of samples
--skip_save do not save individual samples. For speed measurements.
--ddim_steps DDIM_STEPS
number of ddim sampling steps
--plms use plms sampling
--laion400m uses the LAION400M model
--fixed_code if enabled, uses the same starting code across samples
--ddim_eta DDIM_ETA ddim eta (eta=0.0 corresponds to deterministic sampling
--n_iter N_ITER 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
--n_samples N_SAMPLES
how many samples to produce for each given prompt. A.k.a. batch size
--n_rows N_ROWS rows in the grid (default: n_samples)
--scale SCALE unconditional guidance scale: eps = eps(x, empty) + scale * (eps(x, cond) - eps(x, empty))
--from-file FROM_FILE
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
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.
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 |
GitHub | arXiv | Project page
See more in the original repository