Phase 04: Computer Vision

Image Generation — GANs

A GAN is two neural networks in a fixed game. One draws, one critiques. They get better together until the drawings fool the critic. Explain the minimax game between generator and discriminator and why the equilibrium corresponds to pmodel = pdata. Implement a DCGAN in PyTorch and get it to generate coherent 32x32 synthetic images in under 60 lines. Stabilise GAN training with the three standard tricks: non-saturating loss, spectral norm, TTUR (two-timescale update rule). Read training curves that distinguish healthy convergence from mode collapse, oscillation, and discriminator-wins-completely. Classification teaches a network to map images to labels. Generation inverts the problem: sample new images that look like they came from the same distribution. There is no "correct" output you can diff against; there is only a distribution you want to mimic. The standard loss functions (MSE, cross-entropy) cannot measure "did this sample come from the real distribution." Minimising per-pixel error produces blurry averages, not realistic samples. The breakthrough was to learn the loss: train a second network whose job is to tell real from fake, and use its judgement to push the generator. GANs (Goodfellow et al., 2014) defined that framework. By 2018 StyleGAN was producing 1024x1024 faces indistinguishable from photographs. Diffusion models have since taken the throne on quality and controllability, but every trick that makes diffusion practical —…

Image Generation — GANs: A GAN is two neural networks in a fixed game. One draws, one critiques. They get better together until the drawings fool the critic.

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.