Diffusion models generate images through an iterative denoising process. Add Gaussian noise to images gradually (forward process), then train a model to reverse this process (reverse process). Sampling starts with pure noise and denoises iteratively to generate new images.
Forward Process
x_0 (real image)
↓ (add noise) x_1 (slightly noisy) ↓ (add more noise) x_2 (more noisy) ↓ ... x_T (pure noise)
Reverse Process (Denoising)
Train a neural network to predict and remove noise:
import torch
import torch.nn as nn
class DiffusionModel(nn.Module): def __init__(self): super().__init__() self.encoder = nn.Sequential(...) # Image encoder self.decoder = nn.Sequential(...) # Noise predictor
def forward(self, x_t, t): # x_t: noisy image at step t # Predict and subtract noise noise_pred = self.decoder(self.encoder(x_t)) x_{t-1} = (x_t - noise_pred) / sqrt(alpha_t) return x_{t-1}
Sampling
Start with x_T ~ N(0, I) (pure noise)
For t = T, T-1, ..., 1: x_{t-1} = denoise_model(x_t, t) Return x_0 (generated image)
Conclusion
Diffusion models are the foundation of modern image generation (DALL-E, Stable Diffusion). Understanding the forward/reverse processes explains how denoising generates realistic images. Next: video generation models that extend diffusion to temporal sequences.
