Image Generation — Diffusion Models

A diffusion model learns to denoise. Train it to remove a tiny bit of noise from a noisy image, repeat that backwards a thousand times, and you have an image generator.

Build 1.3 hr Python

Prerequisites: Phase 4 Lesson 07 (U-Net), Phase 1 Lesson 06 (Probability), Phase 3 Lesson 06 (Optimizers)

#Learning Objectives

  • Derive the forward noising process x_0 -> x_1 -> ... -> x_T and explain why the closed-form q(x_t | x_0) holds for any t
  • Implement a DDPM-style training objective that regresses the noise added at each step, and a sampler that walks back from pure noise to an image
  • Build a time-conditioned U-Net (small enough to train on CPU) that predicts the noise for any timestep
  • Explain the difference between DDPM and DDIM sampling, and when each is appropriate (Lesson 23 covers flow matching and rectified flow in depth)
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.