sd_tools

command line tool for stable diffusion


License
MIT
Install
pip install sd_tools==1.4.0

Documentation

sd-tools

generating images from the command line and web UI

web

recording.mp4
pip install sd-tools

Basics

sdxl 'locomotive'

If the model can't be downloaded, try using a huggingface mirror:

export HF_MIRROR=https://hf-mirror.com

To get better result, use more steps and higher resolutions:

sdxl 'locomotive' --size 720 --steps 4

Generate more with --count:

sdxl 'locomotive' --size 1024x576 --steps 4 --count 3

By default, images are save to output/{seed}-{time}.webp, which can be customized via -o:

sdxl 'locomotive' -o 'output/{seed}-{size}-{cfg}-{time}.webp'

Interactive Mode

The loading of the model can task some time, use -i to enter interactive mode, keeping the model loaded:

sdxl 'locomotive' --size 1024x576 --steps 4 -i

Edited prompt and press enter:

> locomotive

size, count, steps and cfg can also be set on the fly:

> locomotive size=1024 cfg=1.9

Web UI

sdxl 'A green frog' \
 --model 'Lykon/dreamshaper-xl-lightning' \
 --scheduler 'DPM++ SDE Karras' \
 --listen 8888

Custom Models

To use a specific model:

sdxl 'locomotive' \
 --model Lykon/dreamshaper-xl-lightning \
 --steps 6 \
 --size 1024x576 \
 --scheduler 'DPM++ SDE Karras' \
 --cfg 2 \

More models can be found on huggingface and civitai, models with Lightning or Turbo can generate image in less than 8 steps.

For models without fp16 variant or safetensor format, add --no-fp16 or --no-safetensor

sdxl 'locomotive' \
 --model RunDiffusion/Juggernaut-XL-Lightning \
 --cfg 1.5 \
 --steps 6 \
 --size 832x1216 \
 --scheduler 'DPM++ SDE' \
 --no-fp16 --no-safetensor

To use models downloaded from civitai:

sdxl 'locomotive' --model ./model.safetensors

Loras

Loras are like plugins for the base model, multiple loras can be used:

sdxl 'locomotive' \
 --model SG161222/RealVisXL_V4.0_Lightning \
 --steps 8 \
 --size 1024x576 \
 --loras ./lora1.safetensors ./lora2.safetensors:0.8 \

Speed Up Generation

Using --lcm, --tcd, --hyper or --lightning to speed up generation, not necessary for turbo/lightning models:

sdxl 'locomotive' \
 --model SG161222/RealVisXL_V4.0 \
 --steps 4 \
 --size 1024x576 \
 --tcd 1 \

More Controlling

Canny

sdxl 'protrait of a man' --canny photo.jpg --canny-low 100 --canny-high 200

Depth

sdxl 'protrait of a man' --depth photo.jpg

Pose

sdxl 'protrait of a man' --pose photo.jpg

Inpainting

sdxl 'helmet' \
 --inpaint test/tesla.webp \
 --inpaint-mask mask.png \
 --steps 40 \
 -i \
 -o output/preview.png

Open mask.png, paint the area to be modified, close image editor, then press Enter to start inpainting.

Style and Face

Photo Maker

pip install 'sd-tools[photomaker]'

use img to indicate the reference target

sdxl 'man img holding a toy car' \
 --model Lykon/dreamshaper-xl-lightning \
 --steps 6 \
 --cfg 2 \
 --photo-maker test/tesla.webp \
 --scheduler 'DPM++ SDE Karras'

multiple reference images can be provided:

--photo-maker 1.png 2.png

IP-Adapter Plus

style reference, multiple images can be used:

sdxl 'portrait of a man' \
 --model Lykon/dreamshaper-xl-lightning \
 --scheduler 'DPM++ SDE Karras' \
 --steps 8 --size 1024x576 \
 --ipa-plus test/ghibli \
 --ipa-plus-scale 0.7 \
 --seed 0

face reference, multiple images can be used:

sdxl 'portrait of a man' \
 --model Lykon/dreamshaper-xl-lightning \
 --scheduler 'DPM++ SDE Karras' \
 --steps 8 --size 1024x576 \
 --ipa-plus-face test/tesla-s.webp \
 --ipa-plus-scale 0.4 \
 --seed 0

combined

sdxl 'portrait of a man' \
 --model Lykon/dreamshaper-xl-lightning \
 --scheduler 'DPM++ SDE Karras' \
 --steps 8 --size 1024x576 \
 --ipa-plus test/ghibli \
 --ipa-plus-face test/tesla-s.webp \
 --ipa-plus-scale 0.7 0.4 \
 --cfg 2 \
 --seed 0

IP-Adapter FaceID Plus

pip install 'sd-tools[faceid]'
sdxl 'man walking on the moon' \
 --model Lykon/dreamshaper-xl-lightning \
 --scheduler 'DPM++ SDE Karras' \
 --steps 6 \
 --cfg 2 \
 --ipa-faceid-plus test/tesla.webp

InstantID

pip install 'sd-tools[faceid]'
sdxl 'man walking on the moon' \
 --model Lykon/dreamshaper-xl-lightning \
 --scheduler 'DPM++ SDE Karras' \
 --steps 6 \
 --cfg 2 \
 --instantid test/tesla.webp

IP Composition Adapeter

sdxl 'Arnold Schwarzenegger' \
 --model Lykon/dreamshaper-xl-lightning \
 --scheduler 'DPM++ SDE Karras' \
 --steps 6 \
 --cfg 1.2 \
 --ip-composition test/tesla.webp

HTTP Server

sdxl 'man walking on the moon' --listen 127.0.0.1:8800

Invoking using curl:

curl '127.0.0.1:8800?prompt=shell&seed=1' > image.webp

Live Preview

sdxl 'locomotive' --size 512 -i -o output/preview.png

Open output folder in Finder, switch to gallery mode, once generated, image preview will be updated.

You can even set a count to generate more images:

> locomotive count=3

To keep the generated images, pass an additional ouput path:

sdxl 'locomotive' --size 512 -i -o output/preview.png 'output/{seed}.webp'

More Examples

Realvis

sdxl 'portrait of a woman img, chinese paint style' \
 --model SG161222/RealVisXL_V4.0_Lightning \
 --steps 6 --size 768x1024 \
 --scheduler 'DPM++ SDE Karras' \
 --cfg 2

DreamShaper

sdxl 'locomotive comming' \
 --model Lykon/dreamshaper-xl-lightning \
 --steps 6 --size 1024x576 \
 --scheduler 'DPM++ SDE Karras' \
 --cfg 2

Juggernaut

sdxl 'portrait of a woman, chinese painting style, Full Body Shot' \
 --model RunDiffusion/Juggernaut-XL-Lightning \
 --cfg 1.9 \
 --steps 6 \
 --size 832x1216 \
 --scheduler 'DPM++ SDE' \
 --no-fp16 --no-safetensor

SD 1.5

sd -h

IP-Adapeter FaceID Portrait

sd 'portrait of man, masterpiece' \
 --model Lykon/dreamshaper-8 \
 --steps 8 \
 --lcm 1 \
 --ipa-portrait photo1.png photo2.png \
 -i

IP-Adapter Plus

sd 'man walking down the street' \
 --model Lykon/dreamshaper-8 \
 --steps 10 \
 --size 760 \
 --ipa-plus-scale 0.8 \
 --ipa-plus-face test/tesla-s.webp \
 --lcm 1

IP-Adapter Plus Face

sd 'man in nature' \
 --model Lykon/dreamshaper-8 \
 --steps 10 \
 --size 760 \
 --ipa-plus-scale 0.8 \
 --ipa-plus test/ghibli \
 --lcm 1

IP Composition Adapeter

sd 'Arnold Schwarzenegger' \
 --model Lykon/dreamshaper-8 \
 --steps 10 \
 --lcm 1 \
 --seed 4 \
 --ip-composition test/tesla.webp

Sketch to Image

image2image-turbo

sd 'ethereal fantasy concept art of cat, magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy' \
  --sketch sketch.png -i -o output/preview.webp

SDXS

SDXS: Real-Time One-Step Latent Diffusion Models with Image Conditions

sd --model zweifisch/sdxs-512-0.9-fp16 'chihuahua' --steps 1 --count 10

YOSO

You Only Sample Once

sd --model 'SG161222/Realistic_Vision_V6.0_B1_noVAE' 'chihuahua' --steps 2 --no-fp16 --no-safetensor --yoso 1 --count 10 --cfg 1