$ cd ../
DDPM Diffusion — bash

user@devops:~$ cat README.md

DDPM Diffusion

# Description

DDPM (Denoising Diffusion Probabilistic Model) implemented from scratch in PyTorch on Fashion-MNIST, the model family behind DALL-E 2 and Stable Diffusion. Core idea: instead of compressing (VAE) or competing (GAN), the model learns to INVERT a noise process. Fixed forward process (no learnable params): q(x_t|x_0) = N(x_t; sqrt(a_bar_t)*x_0, (1-a_bar_t)*I) with a linear schedule beta: 1e-4 → 0.02 over T=200 steps, turning the image into pure noise. Learned reverse process: a UNet (361,905 parameters, 3 levels 16/32/32 channels, sinusoidal time embedding 128→256→128, ResBlocks with GroupNorm+SiLU+time injection, 7x7 bottleneck, F.interpolate upsampling) predicts the noise eps_theta(x_t, t) and subtracts it step by step. Training: loss = MSE(eps, eps_theta), 25 epochs on 4,000 samples on CPU (~9 min), final loss 0.1228 with a smooth monotonic decrease (no mode collapse, unlike GANs). Generation: sample x_T ~ N(0, I) and denoise for 200 steps — 64 new images in 21s. Findings: (1) at t=100 the image is almost destroyed but the estimated x_0 already reveals the garment silhouette — the model sees through the noise; (2) generation is stochastic but coherent (sneakers, trousers, bags), no mode collapse; (3) the reverse process is a gradual reveal: global silhouette first (t≈100), fine details later (t<50); (4) CPU-viable: 361K params + T=200 (vs 1000 in the paper) + 4,000 samples = convergence in 9 min. Includes 7 visualizations: forward diffusion, noise schedule, training curves, 64 generated samples, denoising progress and noise prediction at t=25 and t=100.

# Key features

$ DDPM from scratch in PyTorch: closed forward q(x_t|x_0) + learned reverse p_theta with UNet

$ UNet 361,905 params: 3 levels (16/32/32 ch), sinusoidal time embedding, ResBlocks with GroupNorm + time injection

$ Loss = MSE(eps, eps_theta(x_t, t)): the model only learns to predict the added noise

$ Linear schedule beta: 1e-4 → 0.02 over T=200 steps (vs 1000 in the paper, CPU-friendly)

$ Stochastic generation: sample x_T ~ N(0, I) and denoise — 64 new images in 21s

$ The model sees through noise: at t=100 the estimated x_0 already reveals the garment silhouette

$ Reverse process as a gradual reveal: global silhouette first (t≈100), fine details later (t<50)

$ CPU-optimized: 25 epochs on 4,000 samples in ~9 min, final loss 0.1228 with no mode collapse

# Gallery

Training terminal
DDPM Diffusion - Training terminal
64 images generated from noise
DDPM Diffusion - 64 images generated from noise
Reverse process: from noise to image
DDPM Diffusion - Reverse process: from noise to image
Forward process: image → noise
DDPM Diffusion - Forward process: image → noise
Noise prediction at t=100
DDPM Diffusion - Noise prediction at t=100

# Technologies used

PyTorch Python NumPy Matplotlib Torchvision