DDIM (original) (raw)

Denoising Diffusion Implicit Models (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon.

The abstract from the paper is:

Denoising diffusion probabilistic models (DDPMs) have achieved high quality image generation without adversarial training, yet they require simulating a Markov chain for many steps to produce a sample. To accelerate sampling, we present denoising diffusion implicit models (DDIMs), a more efficient class of iterative implicit probabilistic models with the same training procedure as DDPMs. In DDPMs, the generative process is defined as the reverse of a Markovian diffusion process. We construct a class of non-Markovian diffusion processes that lead to the same training objective, but whose reverse process can be much faster to sample from. We empirically demonstrate that DDIMs can produce high quality samples 10× to 50× faster in terms of wall-clock time compared to DDPMs, allow us to trade off computation for sample quality, and can perform semantically meaningful image interpolation directly in the latent space.

The original codebase can be found at ermongroup/ddim.

DDIMPipeline

class diffusers.DDIMPipeline

< source >

( unet: UNet2DModel scheduler: DDIMScheduler )

Parameters

Pipeline for image generation.

This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods implemented for all pipelines (downloading, saving, running on a particular device, etc.).

__call__

< source >

( batch_size: int = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None eta: float = 0.0 num_inference_steps: int = 50 use_clipped_model_output: typing.Optional[bool] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True ) → ImagePipelineOutput or tuple

Parameters

If return_dict is True, ImagePipelineOutput is returned, otherwise a tuple is returned where the first element is a list with the generated images

The call function to the pipeline for generation.

Example:

from diffusers import DDIMPipeline import PIL.Image import numpy as np

load model and scheduler

pipe = DDIMPipeline.from_pretrained("fusing/ddim-lsun-bedroom")

run pipeline in inference (sample random noise and denoise)

image = pipe(eta=0.0, num_inference_steps=50)

process image to PIL

image_processed = image.cpu().permute(0, 2, 3, 1) image_processed = (image_processed + 1.0) * 127.5 image_processed = image_processed.numpy().astype(np.uint8) image_pil = PIL.Image.fromarray(image_processed[0])

save image

image_pil.save("test.png")

ImagePipelineOutput

class diffusers.ImagePipelineOutput

< source >

( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )

Parameters

Output class for image pipelines.

< > Update on GitHub