# 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: 1. Take a real image x₀. 2. Select a random timestep t. 3. Generate Gaussian noise ε. 4. Create xₜ using the forward diffusion process. 5. Give xₜ and t to the U-Net. 6. Predict the noise. 7. Calculate MSE between predicted and actual noise. 8. 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