YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
DDPM β Fashion-MNIST
A simple DDPM implementation built from scratch using PyTorch.
The model learns to predict the noise added to a real Fashion-MNIST image.
Pipeline
Training:
xβ β add noise β xβ β U-Net β predicted noise
β
MSE Loss
Sampling:
Gaussian Noise
β
U-Net
β
Denoising
β
U-Net
β
...
β
Generated Image
Model
The U-Net takes:
(xβ, t)
and predicts:
Ρθ(xβ, t)
The U-Net contains:
- Time embedding
- Input convolution
- 2 downsampling blocks
- 2 middle ResBlocks
- 2 upsampling blocks
- Skip connections
- GroupNorm
- SiLU activation
- Final output convolution
Input:
[B, 1, 28, 28]
Output:
[B, 1, 28, 28]
The output represents predicted Gaussian noise.
Forward Diffusion
We use:
xβ = βΞ±Μβ xβ + β(1 - Ξ±Μβ) Ξ΅
where:
Ξ΅ ~ N(0, I)
Training
For every batch:
- Take a real image xβ.
- Select a random timestep t.
- Generate Gaussian noise Ξ΅.
- Create xβ using the forward diffusion process.
- Give xβ and t to the U-Net.
- Predict the noise.
- Calculate MSE between predicted and actual noise.
- Update the U-Net.
Reverse Diffusion
During generation, we start from:
xT ~ N(0, I)
and move backwards:
xT β xT-1 β ... β x1 β x0
At every timestep, the U-Net predicts the noise and the DDPM scheduler performs one reverse step.
Checkpoint
Model weights are saved using:
.safetensors
Example:
checkpoints/ddpm_fashion_mnist.safetensors
The model architecture must be recreated before loading the weights.
Dataset
Dataset:
Fashion-MNIST
Image size:
28 Γ 28
Channels:
1
Goal
The goal of this project is to understand DDPM from first principles:
Forward Diffusion
β
U-Net
β
Noise Prediction
β
Reverse Diffusion
β
Image Generation