Generate images from text (txt2img) or from other images (img2img)
- stable-diffusion: https://github.com/CompVis/stable-diffusion (
/opt/stable-diffusion
) - with memory optimizations: https://github.com/basujindal/stable-diffusion (
/opt/stable-diffusion/optimizedSD
) - tested on
stable-diffusion-1.4
model: https://huggingface.co/CompVis/stable-diffusion-v-1-4-original
See the stable-diffusion-webui
container for a faster implementation with a web interface.
Download the stable-diffusion-1.4 model (sd-v1-4.ckpt
)
wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt -O /data/models/stable-diffusion/sd-v1-4.ckpt
Then run this in the container to generate images (by default, six 512x512 images with 50 refinement steps)
cd /opt/stable-diffusion && python3 scripts/txt2img.py --plms \
--ckpt /data/models/stable-diffusion/sd-v1-4.ckpt \
--outdir /data/images/stable-diffusion \
--prompt "a photograph of an astronaut riding a horse"
See here for options: https://github.com/CompVis/stable-diffusion#reference-sampling-script
For just one 512x512 image with 25 steps:
cd /opt/stable-diffusion && python3 scripts/txt2img.py --plms \
--n_samples 1 --n_iter 1 --ddim_steps 25 \
--ckpt /data/models/stable-diffusion/sd-v1-4.ckpt \
--outdir /data/images/stable-diffusion \
--prompt "two robots walking in the woods"
- Change the image resolution with
--W
and--H
(the default is 512x512) - Change the
--seed
to have the images be different (the default seed is 42)
For Jetson Orin Nano and reduced memory usage:
cd /opt/stable-diffusion && python3 optimizedSD/optimized_txt2img.py \
--sampler plms --seed 42 \
--n_samples 1 --n_iter 1 --ddim_steps 25 \
--ckpt /data/models/stable-diffusion/sd-v1-4.ckpt \
--outdir /data/images/stable-diffusion \
--prompt "a photograph of an astronaut riding a horse"
To run all these steps from a script, see stable-diffusion/test.sh
CONTAINERS
stable-diffusion |
|
---|---|
Builds | |
Requires | L4T ['>=34.1.0'] |
Dependencies | build-essential cuda cudnn python numpy cmake onnx pytorch:2.2 torchvision huggingface_hub rust transformers |
Dependants | l4t-diffusion |
Dockerfile | Dockerfile |
Images | dustynv/stable-diffusion:r35.2.1 (2023-12-14, 6.1GB) dustynv/stable-diffusion:r35.3.1 (2023-12-12, 6.1GB) dustynv/stable-diffusion:r35.4.1 (2023-12-15, 6.1GB) |
Notes | disabled on JetPack 4 |
CONTAINER IMAGES
Repository/Tag | Date | Arch | Size |
---|---|---|---|
dustynv/stable-diffusion:r35.2.1 |
2023-12-14 |
arm64 |
6.1GB |
dustynv/stable-diffusion:r35.3.1 |
2023-12-12 |
arm64 |
6.1GB |
dustynv/stable-diffusion:r35.4.1 |
2023-12-15 |
arm64 |
6.1GB |
Container images are compatible with other minor versions of JetPack/L4T:
• L4T R32.7 containers can run on other versions of L4T R32.7 (JetPack 4.6+)
• L4T R35.x containers can run on other versions of L4T R35.x (JetPack 5.1+)
RUN CONTAINER
To start the container, you can use jetson-containers run
and autotag
, or manually put together a docker run
command:
# automatically pull or build a compatible container image
jetson-containers run $(autotag stable-diffusion)
# or explicitly specify one of the container images above
jetson-containers run dustynv/stable-diffusion:r35.4.1
# or if using 'docker run' (specify image and mounts/ect)
sudo docker run --runtime nvidia -it --rm --network=host dustynv/stable-diffusion:r35.4.1
jetson-containers run
forwards arguments todocker run
with some defaults added (like--runtime nvidia
, mounts a/data
cache, and detects devices)
autotag
finds a container image that's compatible with your version of JetPack/L4T - either locally, pulled from a registry, or by building it.
To mount your own directories into the container, use the -v
or --volume
flags:
jetson-containers run -v /path/on/host:/path/in/container $(autotag stable-diffusion)
To launch the container running a command, as opposed to an interactive shell:
jetson-containers run $(autotag stable-diffusion) my_app --abc xyz
You can pass any options to it that you would to docker run
, and it'll print out the full command that it constructs before executing it.
BUILD CONTAINER
If you use autotag
as shown above, it'll ask to build the container for you if needed. To manually build it, first do the system setup, then run:
jetson-containers build stable-diffusion
The dependencies from above will be built into the container, and it'll be tested during. Run it with --help
for build options.