Denoising Diffusion Probabilistic Models (DDPM)
DDPM is the foundation of modern generative AI (like Stable Diffusion and Midjourney). It works by destroying data with noise and then learning to reverse that destruction.
1. The Forward Process ()
In the forward process, we take a clean image and slowly add Gaussian noise over timesteps.
- : The variance schedule. Usually, we increase as increases (linear or cosine schedule).
- The Result: By the time we reach , the image is indistinguishable from pure white noise.
2. The Reverse Process ()
This is where the magic happens. We train a neural network (typically a U-Net) to predict the noise that was added at each step. If the network can predict the noise , we can subtract it to get back to a slightly cleaner image.
The transition is modeled as:
3. The Training Objective
Surprisingly, the complex math of Diffusion simplifies into a very elegant loss function. Instead of predicting the image directly, we predict the noise that was sampled at timestep .
Intuition: We are telling the network: "Here is a messy, noisy image. Can you guess exactly what the random noise was that made it look this way?"
4. The Architecture: Why U-Net?
Diffusion models almost always use a U-Net architecture with Attention layers.
- Downsampling: The network looks at the global structure (the "big picture").
- Upsampling: The network reconstructs the fine details (the "texture").
- Skip Connections: These are vital. They allow the network to keep the original spatial information while it's trying to figure out what's noise and what's data.
- Time Embeddings: Since the network needs to know how much noise to expect, we inject the timestep into every layer using sinusoidal embeddings (similar to Transformers).
Summary of the DDPM Recipe
- Pick an image from your dataset.
- Pick a random timestep between 1 and .
- Add noise to the image to create .
- Ask the U-Net to guess given and .
- Update the U-Net based on how wrong its guess was.
To make the model generate specific things (like "a cat in a hat"), we inject Text Embeddings (from a model like CLIP) into the U-Net. This is called Guided Diffusion.