🎨"Denoising Diffusion Probabilistic Models" paper implementation.
Denoising Diffusion Probabilistic Models (DDPM) are a class of generative models that learn a diffusion process to generate samples. The model iteratively applies a diffusion process to noise, gradually transforming it into samples from the target distribution. This approach has shown promising results in generating high-quality images and has garnered attention in the field of generative modeling.
def add_noise(self,
original_samples: torch.FloatTensor,
timestep: torch.IntTensor):
alphas_cumlative_product = self.alphas_cumlative_product.to(device = original_samples.device, dtype = original_samples.dtype)
timestep = timestep.to(original_samples.device)
alphas_cumlative_product_squaroot = alphas_cumlative_product[timestep] ** 0.5
alphas_cumlative_product_squaroot = alphas_cumlative_product_squaroot.flatten()
while len(alphas_cumlative_product_squaroot.shape) < len(original_samples.shape):
alphas_cumlative_product_squaroot = alphas_cumlative_product_squaroot.unsqueeze(-1)
alphas_cumlative_product_squaroot_mins_one = (1 - alphas_cumlative_product[timestep]) ** 0.5
alphas_cumlative_product_squaroot_mins_one = alphas_cumlative_product_squaroot_mins_one.flatten()
while len(alphas_cumlative_product_squaroot_mins_one.shape) < len(original_samples.shape):
alphas_cumlative_product_squaroot_mins_one = alphas_cumlative_product_squaroot_mins_one.unsqueeze(-1)
noise = torch.randn(original_samples.shape, generator=self.generator, device=original_samples.device, dtype=original_samples.dtype)
noisy_samples = alphas_cumlative_product_squaroot * original_samples + alphas_cumlative_product_squaroot_mins_one * noise
return noisy_samples
class GaussingDitribution:
def __init__(self, paramenters: torch.Tensor) -> None:
self.mean, log_variance = torch.chunk(paramenters, 2, dim = 1)
self.log_variance = torch.clamp(log_variance, -30.0, 20.0)
self.std = torch.exp(0.5 * self.log_variance)
def sample(self):
return self.mean + self.std * torch.rand_like(self.std)
@misc{ho2020denoising,
title = {Denoising Diffusion Probabilistic Models},
author = {Jonathan Ho and Ajay Jain and Pieter Abbeel},
year = {2020},
eprint = {2006.11239},
archivePrefix = {arXiv},
primaryClass = {cs.LG}
}
original_paper: "Denoising Diffusion Probabilistic Models" by Jonathan Ho, Ajay Jain, and Pieter Abbeel.