Phase 04: Computer Vision

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. Derive the forward noising process x0 -> x1 -> ... -> xT and explain why the closed-form q(xt | x0) 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). GANs generate one-shot: noise in, image out, one forward pass. They are fast and hard to train. Diffusion models generate iteratively: start from pure noise, denoise in small steps, image emerges. They are slow and easy to train. For the last five years the latter property has dominated: any small team can train a diffusion model and get reasonable samples; GAN training is a craft you learn over years of failed runs. Beyond training stability, diffusion's iterative structure is what unlocks everything modern image generation does: text conditioning, inpainting, image editing, super-resolution, controllable style. Each step of the sampling loop…

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…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.