diffusion_models.gaussian_diffusion.base_diffuser

Module Contents

class BaseDiffuser(beta_scheduler, prediction_type=PredictionType.Epsilon)[source]

Initializes the object with the specified beta scheduler.

BaseDiffuser is an abstract base class for different diffuser implementations. It defines the interface that all diffusers should adhere to.

Parameters:

Warning

Do not instantiate this class directly. Instead, build your own Diffuser by inheriting from BaseDiffuser. (see GaussianDiffuser)

beta_scheduler: BaseBetaScheduler[source]

The beta scheduler used by the diffuser.

prediction_type: PredictionType[source]

the noise (epsilon) or the velocity (v).

Type:

What the model predicts

get_target(images, noise, timesteps)[source]

The regression target of the model for the configured prediction type.

Parameters:
  • images (Tensor) – The clean images.

  • noise (Tensor) – The noise that was added to them (from diffuse_batch()).

  • timesteps (Tensor) – The timesteps used for diffusion.

Returns:

The noise for "epsilon", or the velocity \(v = \sqrt{\bar{\alpha}_t}\epsilon - \sqrt{1 - \bar{\alpha}_t}x_0\) for "v".

Return type:

Tensor

to_epsilon_and_x0(output, images, timesteps)[source]

Convert a model output into a noise estimate and a clean-image estimate.

Parameters:
  • output (Tensor) – The model prediction.

  • images (Tensor) – The noisy images the model was given.

  • timesteps (Tensor) – The timesteps the model was given.

Returns:

(epsilon, x0). x0 is None for "epsilon" models, as it cannot be computed where \(\bar{\alpha}_t = 0\).

Return type:

Tuple[Tensor, Optional[Tensor]]

property steps: List[int][source]
Abstractmethod:

Returns the list of steps used in the denoising process.

abstract get_timestep(number_of_images, idx)[source]

Get timestep information used for denoising.

abstract diffuse_batch(images)[source]

Diffuse a batch of images.

Parameters:

images (Tensor) – A tensor containing a batch of images.

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]

abstract denoise_batch(images, model)[source]

Denoise a batch of images.

Parameters:
  • images (Tensor) – A tensor containing a batch of images to denoise.

  • model (BaseDiffusionModel) – The model to be used for denoising.

Returns:

A list of tensors containing a batch of denoised images.

Return type:

List[Tensor]

abstract to(device='cpu')[source]

Moves the data to the specified device.

This performs a similar behaviour to the to method of PyTorch.

Parameters:

device (str) – The device to which the method should move the data. It should be a string indicating the desired device. Default is “cpu”.