Skip to main content

Latent diffusion model training and inference tools.

Project description

latent-diffusion-tools

latent-diffusion-tools is a compact latent diffusion training and inference package for Python experiments.

It provides:

  • a small latent diffusion model builder with checkpoint-aware setup
  • a command-line fine-tuning loop for image folders and .npz arrays
  • a command-line sample generation workflow
  • Python APIs for model construction, training, and prediction

Install

For the remote notebook workflow where dependencies are prepared separately:

!python -m pip install --no-deps latent-diffusion-tools

For a local environment where dependency resolution is desired:

pip install latent-diffusion-tools

Build a Model

from latent_diffusion_tools import model

net = model(pretrained=True, root="./ckpt/")

pretrained=True builds the latent diffusion module, prepares the bundled checkpoint, and records the prepared checkpoint path on net.checkpoint_path.

Use pretrained=False when training from scratch.

from latent_diffusion_tools import model

net = model(pretrained=False)

Training

Training input can be an image directory or a directory of .npz files.

Image files may be .png, .jpg, .jpeg, .bmp, .tif, or .tiff.

Each .npz file should include one of these array keys:

  • image
  • img
  • data
  • x

Command line:

latent-diffusion-train ^
  --data-dir .\train_images ^
  --output-dir .\runs\latent_diffusion ^
  --epochs 5 ^
  --batch-size 4 ^
  --lr 1e-4 ^
  --image-size 64 ^
  --checkpoint-root .\ckpt

The command uses the bundled checkpoint setup by default and writes latest.pt to the output directory.

Python usage:

from latent_diffusion_tools import fit

net, history = fit(
    data_dir="./train_images",
    output_dir="./runs/latent_diffusion",
    epochs=5,
    batch_size=4,
    lr=1e-4,
    image_size=64,
    checkpoint_root="./ckpt",
)

Inference

Generate samples with the default model setup:

latent-diffusion-infer ^
  --output-dir .\runs\latent_diffusion_samples ^
  --count 8 ^
  --image-size 64 ^
  --steps 16 ^
  --root .\ckpt

Use a fine-tuned checkpoint produced by latent-diffusion-train:

latent-diffusion-infer ^
  --output-dir .\runs\latent_diffusion_samples ^
  --checkpoint .\runs\latent_diffusion\latest.pt ^
  --count 8 ^
  --image-size 64 ^
  --steps 16 ^
  --root .\ckpt

Python usage:

from latent_diffusion_tools import predict

paths = predict(
    output_dir="./runs/latent_diffusion_samples",
    count=8,
    image_size=64,
    steps=16,
    root="./ckpt",
)
print(paths)

Checkpoint Utilities

The model API prepares the bundled checkpoint automatically when pretrained=True.

Manual preparation is also available:

from latent_diffusion_tools import prepare_checkpoint

checkpoint_path = prepare_checkpoint(root="./ckpt")
print(checkpoint_path)

Attribution

This package is inspired by the latent diffusion training and sampling workflow from CompVis latent-diffusion.

The implementation here is a compact training and inference package for practical experiments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latent_diffusion_tools-0.1.1.tar.gz (99.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latent_diffusion_tools-0.1.1-py3-none-any.whl (99.7 MB view details)

Uploaded Python 3

File details

Details for the file latent_diffusion_tools-0.1.1.tar.gz.

File metadata

  • Download URL: latent_diffusion_tools-0.1.1.tar.gz
  • Upload date:
  • Size: 99.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for latent_diffusion_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cf4735deef0d1a047e892fccd5363924bf0d062ac6a646612f8f6c462c19a701
MD5 e9e1f893b92386ec97e2f2adfd06151b
BLAKE2b-256 8ef01bdfbadf0a4ce24e01b01484c64a488b71ec645baab67fb238dfc9b35c42

See more details on using hashes here.

File details

Details for the file latent_diffusion_tools-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for latent_diffusion_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8425fabaa711897dd58f3f4a9789bceb274403b6ec3d5af9d728c7742906645
MD5 882a056666b3284b48174aeeef62e2f1
BLAKE2b-256 83bd759dcbe59efbfcacb21e2e91d948a7e95792056633c2ddaf46f47efd8f26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page