Files
diffusers/docs/source/en/using-diffusers/unconditional_image_generation.md
Steven Liu cc5b31ffc9
Some checks failed
Run dependency tests / check_dependencies (push) Waiting to run
Run Torch dependency tests / check_torch_dependencies (push) Waiting to run
Fast GPU Tests on main / Setup Torch Pipelines CUDA Slow Tests Matrix (push) Waiting to run
Fast GPU Tests on main / Torch Pipelines CUDA Tests (push) Blocked by required conditions
Fast GPU Tests on main / Torch CUDA Tests (lora) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (models) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (others) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (schedulers) (push) Waiting to run
Fast GPU Tests on main / Torch CUDA Tests (single_file) (push) Waiting to run
Fast GPU Tests on main / PyTorch Compile CUDA tests (push) Waiting to run
Fast GPU Tests on main / PyTorch xformers CUDA tests (push) Waiting to run
Fast GPU Tests on main / Examples PyTorch CUDA tests on Ubuntu (push) Waiting to run
Fast tests on main / ${{ matrix.config.name }} (map[framework:pytorch image:diffusers/diffusers-pytorch-cpu name:Fast PyTorch CPU tests on Ubuntu report:torch_cpu runner:aws-general-8-plus]) (push) Waiting to run
Fast tests on main / ${{ matrix.config.name }} (map[framework:pytorch_examples image:diffusers/diffusers-pytorch-cpu name:PyTorch Example CPU tests on Ubuntu report:torch_example_cpu runner:aws-general-8-plus]) (push) Waiting to run
Secret Leaks / trufflehog (push) Waiting to run
Update Diffusers metadata / update_metadata (push) Waiting to run
Build documentation / build (push) Has been cancelled
[docs] Migrate syntax (#12390)
* change syntax

* make style
2025-09-30 10:11:19 -07:00

2.2 KiB

Unconditional image generation

open-in-colab

Unconditional image generation generates images that look like a random sample from the training data the model was trained on because the denoising process is not guided by any additional context like text or image.

To get started, use the [DiffusionPipeline] to load the anton-l/ddpm-butterflies-128 checkpoint to generate images of butterflies. The [DiffusionPipeline] downloads and caches all the model components required to generate an image.

from diffusers import DiffusionPipeline

generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128").to("cuda")
image = generator().images[0]
image

Tip

Want to generate images of something else? Take a look at the training guide to learn how to train a model to generate your own images.

The output image is a PIL.Image object that can be saved:

image.save("generated_image.png")

You can also try experimenting with the num_inference_steps parameter, which controls the number of denoising steps. More denoising steps typically produce higher quality images, but it'll take longer to generate. Feel free to play around with this parameter to see how it affects the image quality.

image = generator(num_inference_steps=100).images[0]
image

Try out the Space below to generate an image of a butterfly!