Denoising Diffusion Probabilistic Model(DDPM)

Abhishek Kumar Pandey
5 min readJun 7, 2024

--

Easy:

Imagine you have a picture, and you spill a little bit of ink on it. The picture is still kind of clear, but there’s a small smudge. Now, if you keep spilling more and more ink on it, eventually, the picture gets so messy that you can’t see it anymore.

Now, let’s say we want to clean the picture back to its original state. We could do this by carefully removing the ink smudges, little by little, until we see the clear picture again.

A Denoising Diffusion Probabilistic Model (DDPM) works kind of like this. It starts with a clear picture and adds a little bit of noise (like the ink) in many small steps until the picture is completely noisy and unrecognizable. Then, it learns how to reverse this process: it removes the noise step by step, going backwards, until it gets back to the original, clear picture.

In simple terms, DDPM is a way for a computer to learn how to clean up a messy picture by practicing how to make a clear picture messy and then cleaning it up again. This helps the computer get really good at fixing messy pictures!

A Clean Picture

Moderate:

Alright, let’s dive into Denoising Diffusion Probabilistic Models (DDPMs) with a bit more detail, while still keeping it simple and accessible.

What is a DDPM?

A Denoising Diffusion Probabilistic Model (DDPM) is a type of machine learning model used to generate data, such as images, by learning to reverse a process that adds noise to the data. It’s a part of a broader class of models known as generative models.

The Two Main Processes in DDPM

  1. Forward Diffusion Process:
    - Start with a clean image.
    - Gradually add noise to the image in many small steps. This makes the image more and more noisy until it becomes pure noise and the original image is unrecognizable.
    - Each step adds a tiny bit more noise to the image.
  2. Reverse Diffusion Process:
    - Start with a noisy image (which looks like pure noise).
    - Gradually remove the noise in small steps to recover the original image.
    - Each step denoises the image a little bit, making it clearer over time.

How It Works

  1. Training Phase:
    - The model is trained using a large dataset of images.
    - During training, the model learns both the forward process (how to add noise) and the reverse process (how to remove noise).
    - The model learns to predict how to denoise an image at each step by looking at many examples.
  2. Generation Phase:
    - Start with a random noisy image.
    - Apply the reverse diffusion process to gradually remove the noise.
    - After many steps, a clear and coherent image is generated.

Why It’s Effective

  • Step-by-Step Process: By breaking down the noise addition and removal into many small steps, the model can learn to denoise images very effectively.
  • Probabilistic Nature: The model doesn’t just learn a single way to denoise an image but understands the distribution of possible clean images that could result from noisy ones.

Practical Example

Imagine you have a blurry, noisy picture of a cat. A DDPM would start with an extremely noisy version of the cat picture (almost unrecognizable). It would then slowly clean up the noise, step by step, until you can clearly see the cat again. The model gets very good at this because it has practiced on thousands or millions of images.

Conclusion

In essence, a DDPM is like a master artist who can take a completely messy and noisy canvas and, with many small and careful strokes, turn it into a beautiful, clear picture. This ability to reverse the noise addition process step by step makes DDPMs powerful tools for generating high-quality images and other types of data.

Hard:

A Denoising Diffusion Probabilistic Model (DDPM) is a type of generative machine learning model that uses a sequence of steps to convert random noise into a sample from a target distribution. The basic idea behind DDPMs is to gradually remove noise from a noisy input signal, step by step, until we reach the desired output signal. This process is also sometimes called “denoising diffusion”.

Here’s how DDPMs work in more detail:

  1. First, we define a forward diffusion process that adds Gaussian noise to a datapoint at each timestep. We typically use a fixed schedule of variances for adding noise, which increases as the number of timesteps increases. At the beginning of this process, the original datapoint is completely corrupted by noise, while at the end of the process, the resulting signal is pure white noise.
  2. Next, we train a neural network to predict the added noise given a noisy version of a training example. Specifically, we take a noisy input signal, generated according to the forward diffusion process described above, and feed it through the network to produce a prediction of the noise. We train this network to minimize the L2 loss between its predictions and the true values of the added noise.
  3. Once we have trained this network, we can use it to perform denoising diffusion starting from pure white noise. To do this, we run the forward diffusion process backward in time, applying the learned denoiser at each timestep to progressively remove noise from the current estimate of the signal. By the end of this process, we should arrive at a good approximation of the original signal.
  4. Finally, we can use this same approach to generate new samples from the target distribution. Starting from pure white noise, we apply the reverse diffusion process to iteratively refine our estimate of the signal. After many such steps, we will obtain a new sample drawn from the target distribution.

One key advantage of DDPMs is that they can handle complex, high-dimensional distributions without requiring any explicit modeling of the dependencies between different dimensions. Instead, the model learns to gradually denoise the input signal, allowing it to capture intricate structure in the data. Additionally, since DDPMs operate on continuous signals rather than discrete objects like pixels, they can potentially generate higher quality outputs compared to traditional pixel-based methods. However, DDPMs do require significant computational resources to train and sample from, making them somewhat impractical for certain applications.

If you want you can support me: https://buymeacoffee.com/abhi83540

If you want such articles in your email inbox you can subscribe to my newsletter: https://abhishekkumarpandey.substack.com/

A few books on deep learning that I am reading:

Book 1

Book 2

Book 3

--

--