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:
beta_scheduler (BaseBetaScheduler) – The beta scheduler used by the diffuser.
prediction_type (PredictionType) – What the model is trained to predict, either the added noise (
"epsilon") or the velocity ("v", see “Progressive Distillation for Fast Sampling of Diffusion Models”).
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:
- to_epsilon_and_x0(output, images, timesteps)[source]
Convert a model output into a noise estimate and a clean-image estimate.
- Parameters:
- Returns:
(epsilon, x0).x0isNonefor"epsilon"models, as it cannot be computed where \(\bar{\alpha}_t = 0\).- Return type:
- property steps: List[int][source]
- Abstractmethod:
Returns the list of steps used in the denoising process.
- 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]