| # 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 | |