{"id":13524908,"url":"https://github.com/fboulnois/stable-diffusion-docker","last_synced_at":"2025-04-13T07:51:23.250Z","repository":{"id":57863087,"uuid":"527796682","full_name":"fboulnois/stable-diffusion-docker","owner":"fboulnois","description":"Run the official Stable Diffusion releases in a Docker container with txt2img, img2img, depth2img, pix2pix, upscale4x, and inpaint.","archived":false,"fork":false,"pushed_at":"2023-12-29T01:36:15.000Z","size":682,"stargazers_count":743,"open_issues_count":8,"forks_count":131,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-04T05:08:38.591Z","etag":null,"topics":["dall-e","dalle","diffusion","docker","generative-art","huggingface","image-generation","inpainting","midjourney","pytorch","stable-diffusion","tensorflow","text-to-image"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fboulnois.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-23T01:57:45.000Z","updated_at":"2025-03-20T10:23:21.000Z","dependencies_parsed_at":"2023-12-29T02:57:32.863Z","dependency_job_id":null,"html_url":"https://github.com/fboulnois/stable-diffusion-docker","commit_stats":{"total_commits":233,"total_committers":2,"mean_commits":116.5,"dds":"0.0042918454935622075","last_synced_commit":"cbd70bd30d8e18c7673ca5b7540bc1cd665693c9"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fstable-diffusion-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fstable-diffusion-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fstable-diffusion-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fboulnois%2Fstable-diffusion-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fboulnois","download_url":"https://codeload.github.com/fboulnois/stable-diffusion-docker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681494,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dall-e","dalle","diffusion","docker","generative-art","huggingface","image-generation","inpainting","midjourney","pytorch","stable-diffusion","tensorflow","text-to-image"],"created_at":"2024-08-01T06:01:14.462Z","updated_at":"2025-04-13T07:51:23.209Z","avatar_url":"https://github.com/fboulnois.png","language":"Python","funding_links":[],"categories":["HarmonyOS","6. 自建教程"],"sub_categories":["Windows Manager","自建教程"],"readme":"# Stable Diffusion in Docker\n\nRun the official [Stable Diffusion](https://huggingface.co/CompVis/stable-diffusion)\nreleases on [Huggingface](https://huggingface.co/) in a GPU accelerated Docker\ncontainer.\n\n```sh\n./build.sh run 'An impressionist painting of a parakeet eating spaghetti in the desert'\n```\n\n![An impressionist painting of a parakeet eating spaghetti in the desert 1](https://raw.githubusercontent.com/fboulnois/repository-assets/main/assets/stable-diffusion-docker/An_impressionist_painting_of_a_parakeet_eating_spaghetti_in_the_desert_s1.png)\n![An impressionist painting of a parakeet eating spaghetti in the desert 2](https://raw.githubusercontent.com/fboulnois/repository-assets/main/assets/stable-diffusion-docker/An_impressionist_painting_of_a_parakeet_eating_spaghetti_in_the_desert_s2.png)\n\n```sh\n./build.sh run --image parakeet_eating_spaghetti.png --strength 0.6 'Bouquet of roses'\n```\n\n![Bouquet of roses 1](https://raw.githubusercontent.com/fboulnois/repository-assets/main/assets/stable-diffusion-docker/Bouquet_of_roses_s1.png)\n![Bouquet of roses 2](https://raw.githubusercontent.com/fboulnois/repository-assets/main/assets/stable-diffusion-docker/Bouquet_of_roses_s2.png)\n\n## Before you start\n\n### Minimum requirements\n\nBy default, the pipeline uses the full model and weights which requires a CUDA\ncapable GPU with 8GB+ of VRAM. It should take a few seconds to create one image.\nOn less powerful GPUs you may need to modify some of the options; see the\n[Examples](#examples) section for more details. If you lack a suitable GPU you\ncan set the options `--device cpu` and `--onnx` instead.\n\n### Huggingface token\n\nSince it uses the official model, you will need to create a [user access token](https://huggingface.co/docs/hub/security-tokens)\nin your [Huggingface account](https://huggingface.co/settings/tokens). Save the\nuser access token in a file called `token.txt` and make sure it is available\nwhen building the container. The token content should begin with `hf_...`\n\n## Quickstart\n\nThe pipeline is managed using a single [`build.sh`](build.sh) script.\n\nPull the latest version of `stable-diffusion-docker` using `./build.sh pull`.\nYou will need to use the option `--token` to specify a valid [user access token](#huggingface-token)\nwhen using [`./build run`](#run).\n\nAlternately, build the image locally before running it.\n\n## Build\n\nMake sure your [user access token](#huggingface-token) is saved in a file called\n`token.txt`.\n\nTo build:\n\n```sh\n./build.sh build  # or just ./build.sh\n```\n\n## Run\n\n### Text-to-Image (`txt2img`)\n\nCreate an image from a text prompt.\n\nTo run:\n\n```sh\n./build.sh run 'Andromeda galaxy in a bottle'\n```\n\n### Image-to-Image (`img2img`)\n\nCreate an image from an existing image and a text prompt.\n\nFirst, copy an image to the `input` folder. Next, to run:\n\n```sh\n./build.sh run --image image.png 'Andromeda galaxy in a bottle'\n```\n\n### Depth-Guided Diffusion (`depth2img`)\n\nModify an existing image with its depth map and a text prompt.\n\nFirst, copy an image to the `input` folder. Next, to run:\n\n```sh\n./build.sh run --model 'stabilityai/stable-diffusion-2-depth' \\\n  --image image.png 'A detailed description of the objects to change'\n```\n\n### Instruct Pix2Pix (`pix2pix`)\n\nModify an existing image with a text prompt.\n\nFirst, copy an image to the `input` folder. Next, to run:\n\n```sh\n./build.sh run --model 'timbrooks/instruct-pix2pix' \\\n  --image image.png 'A detailed description of the objects to change'\n```\n\n### Stable UnCLIP Variations (`unclip`)\n\nCreate different versions of an image with a text prompt.\n\nFirst, copy an image to the `input` folder. Next, to run:\n\n```sh\n./build.sh run --model 'stabilityai/stable-diffusion-2-1-unclip-small' \\\n  --image image.png 'A detailed description of the image'\n```\n\n### Image Upscaling (`upscale4x`)\n\nCreate a high resolution image from an existing image with a text prompt.\n\nFirst, copy an image to the `input` folder. Next, to run:\n\n```sh\n./build.sh run --model 'stabilityai/stable-diffusion-x4-upscaler' \\\n  --image image.png 'Andromeda galaxy in a bottle'\n```\n\n### Diffusion Inpainting (`inpaint`)\n\nModify specific areas of an existing image with an image mask and a text prompt.\n\nFirst, copy an image and an image mask to the `input` folder. White areas of the\nmask will be diffused and black areas will be kept untouched. Next, to run:\n\n```sh\n./build.sh run --model 'runwayml/stable-diffusion-inpainting' \\\n  --image image.png --mask mask.png 'Andromeda galaxy in a bottle'\n```\n\n## Options\n\nThe following are the most common options:\n\n* `--prompt [PROMPT]`: the prompt to render into an image\n* `--model [MODEL]`: the model used to render images (default is\n`CompVis/stable-diffusion-v1-4`)\n* `--height [HEIGHT]`: image height in pixels (default 512, must be divisible by 64)\n* `--width [WIDTH]`: image width in pixels (default 512, must be divisible by 64)\n* `--iters [ITERS]`: number of times to run pipeline (default 1)\n* `--samples [SAMPLES]`: number of images to create per run (default 1)\n* `--scale [SCALE]`: how closely the image should follow the prompt (default 7.5)\n* `--scheduler [SCHEDULER]`: override the scheduler used to denoise the image\n(default `None`)\n* `--seed [SEED]`: RNG seed for repeatability (default is a random seed)\n* `--steps [STEPS]`: number of sampling steps (default 50)\n\nOther options:\n\n* `--attention-slicing`: use less memory but decrease inference speed (default\nis no attention slicing)\n* `--device [DEVICE]`: the cpu or cuda device to use to render images (default\n`cuda`)\n* `--half`: use float16 tensors instead of float32 (default `float32`)\n* `--image [IMAGE]`: the input image to use for image-to-image diffusion\n(default `None`)\n* `--image-scale [IMAGE_SCALE]`: how closely the image should follow the\noriginal image (default `None`)\n* `--mask [MASK]`: the input mask to use for diffusion inpainting (default\n`None`)\n* `--negative-prompt [NEGATIVE_PROMPT]`: the prompt to not render into an image\n(default `None`)\n* `--onnx`: use the onnx runtime for inference (default is off)\n* `--skip`: skip safety checker (default is the safety checker is on)\n* `--strength [STRENGTH]`: diffusion strength to apply to the input image\n(default 0.75)\n* `--token [TOKEN]`: specify a Huggingface user access token at the command line\ninstead of reading it from a file (default is a file)\n* `--vae-slicing`: use less memory when creating large batches of images\n(default is no vae slicing)\n* `--vae-tiling`: use less memory when creating ultra-high resolution images but\nmassively decrease inference speed (default is no vae tiling)\n* `--xformers-memory-efficient-attention`: use less memory but require the\nxformers library (default is that xformers is not required)\n\nSome of the original `txt2img.py` options [have been renamed](https://github.com/fboulnois/stable-diffusion-docker/issues/49)\nfor easy-of-use and compatibility with other pipelines:\n\n| txt2img | stable-diffusion-docker |\n|---------|-------------------------|\n| `--H` | `--height` |\n| `--W` | `--width` |\n| `--n_iter` | `--iters` |\n| `--n_samples` | `--samples` |\n| `--ddim_steps` | `--steps` |\n\n## Examples\n\nThese commands are both identical:\n\n```sh\n./build.sh run 'abstract art'\n./build.sh run --prompt 'abstract art'\n```\n\nSet the seed to 42:\n\n```sh\n./build.sh run --seed 42 'abstract art'\n```\n\nOptions can be combined:\n\n```sh\n./build.sh run --scale 7.0 --seed 42 'abstract art'\n```\n\nMany popular models are supported out-of-the-box:\n\n| Model Name | Option using `--model` |\n|------------|------------------------|\n| [Stable Diffusion 1.4](https://huggingface.co/CompVis/stable-diffusion-v1-4) | `'CompVis/stable-diffusion-v1-4'` |\n| [Stable Diffusion 1.5](https://huggingface.co/runwayml/stable-diffusion-v1-5) | `'runwayml/stable-diffusion-v1-5'` |\n| [Stable Diffusion 2.0](https://huggingface.co/stabilityai/stable-diffusion-2) | `'stabilityai/stable-diffusion-2'` |\n| [Stable Diffusion 2.1](https://huggingface.co/stabilityai/stable-diffusion-2-1) | `'stabilityai/stable-diffusion-2-1'` |\n| [Stable Diffusion XL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) | `'stabilityai/stable-diffusion-xl-base-1.0'` |\n| [OpenJourney 1.0](https://huggingface.co/prompthero/openjourney) | `'prompthero/openjourney'` |\n| [Dreamlike Diffusion 1.0](https://huggingface.co/dreamlike-art/dreamlike-diffusion-1.0) | `'dreamlike-art/dreamlike-diffusion-1.0'` |\n| [and more!](https://huggingface.co/models?other=stable-diffusion\u0026sort=likes) | ... |\n\n```sh\n./build.sh run --model 'prompthero/openjourney' --prompt 'abstract art'\n```\n\nOn systems without enough GPU VRAM, you can try mixing and matching options:\n\n* Give Docker Desktop more resources by increasing the CPU, memory, and swap in\nthe Settings -\u003e Resources section if the container is terminated\n* Make images smaller than 512x512 using `--height` and `--width` to decrease\nmemory use and increase image creation speed\n* Use `--half` to decrease memory use but slightly decrease image quality\n* Use `--attention-slicing` to decrease memory use but also decrease image\ncreation speed\n* Use `--xformers-memory-efficient-attention` to decrease memory use if the\npipeline and the hardware supports the option\n* Decrease the number of samples and increase the number of iterations with\n`--samples` and `--iters` to decrease overall memory use\n* Skip the safety checker with `--skip` to run less code\n\n```sh\n./build.sh run --height 256 --width 256 --half \\\n  --attention-slicing --xformers-memory-efficient-attention \\\n  --samples 1 --iters 1 --skip --prompt 'abstract art'\n```\n\nOn Windows, if you aren't using WSL2 and instead use MSYS, MinGW, or Git Bash,\nprefix your commands with `MSYS_NO_PATHCONV=1` (or export it beforehand):\n\n```sh\nMSYS_NO_PATHCONV=1 ./build.sh run --half --prompt 'abstract art'\n```\n\n## Outputs\n\n### Model\n\nThe model and other files are cached in a volume called `huggingface`. The\nmodels are stored in `\u003cvolume\u003e/diffusers/\u003cmodel\u003e/snapshots/\u003cgithash\u003e/unet/\u003cweights\u003e`.\nCheckpoint files (`ckpt`s) are unofficial versions of the official models, and\nso these are not part of the official release.\n\n### Images\n\nThe images are saved as PNGs in the `output` folder using the prompt text. The\n`build.sh` script creates and mounts this folder as a volume in the container.\n\n## Contributing\n\nSee the [CONTRIBUTING.md](CONTRIBUTING.md) file for more details. In short,\nfollow the style guidelines, agree to the Developer Certificate of Origin, and\nsubmit a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffboulnois%2Fstable-diffusion-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffboulnois%2Fstable-diffusion-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffboulnois%2Fstable-diffusion-docker/lists"}