diffusion_models.gaussian_diffusion.ddimm_diffuser

Module Contents

class DenoisingMode[source]

Initialize self. See help(type(self)) for accurate signature.

Linear = 'linear'[source]
Quadratic = 'quadratic'[source]
Trailing = 'trailing'[source]

Evenly spaced steps that end on the last (pure noise) timestep.

Needed to sample models trained with zero terminal SNR properly; linear and quadratic spacing never reach the final timestep.

class DdimDiffuser(beta_scheduler, mode=DenoisingMode.Quadratic, number_of_steps=20, prediction_type=PredictionType.Epsilon)[source]

Initializes the class instance.

Parameters:
  • beta_scheduler (BaseBetaScheduler) – The beta scheduler instance to be used.

  • mode (DenoisingMode) – How the sampling timesteps are spaced.

  • number_of_steps (int) – Number of denoising steps.

  • prediction_type (PredictionType) – Whether the model predicts the noise or the velocity.

number_of_steps = 20[source]

Number of steps to use in the denoising process.

mode[source]

Linear or Quadratic sampling.

device: str = 'cpu'[source]

The device to use. Defaults to cpu.

property steps: List[int][source]

Returns the list of steps used in the denoising process.

get_timestep(number_of_images, idx)[source]

Get timestep information used for denoising.

classmethod from_checkpoint(checkpoint)[source]

Instantiate a DDIM Diffuser from a training checkpoint.

Parameters:

checkpoint (Checkpoint) – The training checkpoint object containing the trained model’s parameters and configuration.

Returns:

An instance of the DdimDiffuser class initialized with the parameters loaded from the given checkpoint.

Return type:

DdimDiffuser

to(device='cpu')[source]

Moves the data to the specified device.

This performs a similar behaviour to the to method of PyTorch. moving the GaussianDiffuser and the BetaScheduler to the specified device.

Parameters:

device (str) – The device to which the method should move the object. Default is “cpu”.

Example

>>> ddim_diffuser = DdimDiffuser()
>>> ddim_diffuser = ddim_diffuser.to(device="cuda")
diffuse_batch(images)[source]

Diffuse a batch of images.

Diffuse the given batch of images by adding noise based on the beta scheduler.

Parameters:

images (Tensor) –

Batch of images to diffuse.

Shape should be (B, C, H, W).

Returns:

A tuple containing three tensors

  • images: Diffused batch of images.

  • noise: Noise added to the images.

  • timesteps: Timesteps used for diffusion.

Return type:

Tuple[Tensor, Tensor, Tensor]

denoise_batch(images, model)[source]

Denoise a batch of images.

This denoises a batch images. This is the image generation process.

Parameters:
Returns:

A list of tensors containing a batch of denoised images.

Return type:

List[Tensor]