GANs trained generators by playing them against discriminators. They were the dominant generative model from 2014 to 2020 — then diffusion ate their lunch. But in 2025, GANs are quietly returning as fast-sampling distillation targets (StyleGAN-T, GigaGAN) and as the realism backbone of every deepfake detector. Understanding GANs is understanding why modern generation looks the way it does.
Learning Objectives
After this lesson, you will be able to:
Understand the adversarial game: one network creates fakes, the other tries to catch them
Explain the minimax GAN objective and derive why a too-powerful discriminator causes vanishing gradients for the generator
Recognize the common training problems (mode collapse, vanishing gradients, oscillation) and know what causes each
Follow the evolution from the original GAN to WGAN and StyleGAN -- and the key architectural insight at each step
GANs are one of the most creative ideas in all of machine learning. The concept is simple but powerful: instead of defining "good output" with a formula, train a second network to judge quality. Competition drives both networks to improve. If you have ever played a game where you got better because your opponent kept pushing you, you already understand the intuition.
Your Reflection
Saves automatically
What’s one thing you learned? What’s still confusing?
This is a Generative Adversarial Network. The generator is the counterfeiter. The discriminator is the detective. They train together in an adversarial game, and the generator's attempts to fool the discriminator drive it to produce increasingly realistic outputs.
GANs, introduced by Ian Goodfellow in 2014, represent one of the most creative ideas in machine learning: instead of directly optimizing a likelihood function, create a second network whose job is to evaluate the first. Competition breeds excellence. The deep-learning track gives the architectural-engineering view of GANs and VAEs side by sideGAN & VAE FoundationsGANs train a generator-discriminator pair adversarially; VAEs learn an encoder-decoder with a KL-regularized latent prior. The two pre-diffusion deep generative families and the architectures the generative-AI track builds on.Learn more →; this lesson zooms in on the GAN side and the math that drives it.
A GAN consists of two neural networks trained simultaneously:
Generator G: Takes random noise z and transforms it into a fake sample (e.g., an image). Its goal is to produce outputs indistinguishable from real data.
Discriminator D: Takes an input (either real data or a fake from G) and outputs a probability that the input is real. Its goal is to correctly distinguish real from fake.
Try it! Play the "real or AI?" game at whichfaceisreal.com. You are acting as the discriminator -- trying to spot the fake. Notice how hard it is? That means the generator has won the adversarial game. Pay attention to what gives the fakes away (ears, backgrounds, teeth) -- those are exactly the artifacts the discriminator learns to detect.
First term: For real data x, D(x) should be close to 1, making log D(x) close to 0 (maximized).
Second term: For fake data G(z), D(G(z)) should be close to 0, making log(1 - D(G(z))) close to 0 (maximized).
Generator's perspective (minimize)
The generator only controls the second term through G(z).
It wants D(G(z)) to be close to 1 (fool the discriminator), which makes log(1 - D(G(z))) very negative (minimized).
What Do You Think?
What happens if the discriminator becomes perfect (always correctly identifies real vs fake)?
This is the vanishing gradient problem for GANs. When D is too good, D(G(z)) is near 0 for all fakes, and the gradient of log(1 - D(G(z))) with respect to G becomes tiny. The generator cannot improve because it receives almost no learning signal. This is why GAN training is so delicate -- the discriminator must be good enough to provide useful feedback but not so good that it shuts down learning entirely.
A random latent vector z is drawn from a simple distribution (typically a Gaussian). This noise vector is the raw material -- the seed -- from which the generator will attempt to craft a realistic image. Each z produces a different output.
The generator G transforms z into a synthetic image G(z). Early in training, this output is garbage -- random pixel noise with no structure. The generator has not yet learned what real images look like.
A batch of real images from the training set is combined with the generator's fakes. The discriminator will see both, but it does not know which are which. This mixed batch is the discriminator's exam.
The discriminator D evaluates each image and outputs a probability: close to 1.0 for "real" and close to 0.0 for "fake." Early on, the discriminator quickly learns to spot the generator's crude fakes. It assigns high scores to real images and low scores to fakes.
The discriminator loss measures its classification errors: it is penalized for assigning low probability to real images and high probability to fakes. The loss D_loss = -[log D(real) + log(1 - D(fake))] is minimized by correctly identifying both real and fake samples.
The generator loss measures how well its fakes fooled the discriminator. If D(G(z)) is low (discriminator caught the fake), the generator is penalized. The generator minimizes -log D(G(z)), pushing its outputs toward images the discriminator believes are real.
Gradients flow and both networks update their weights. The discriminator sharpens its detection of fakes. The generator adjusts to produce more convincing outputs. Crucially, each update only touches one network at a time -- the other stays frozen. Typically 1-5 discriminator steps per generator step.
The loop repeats for thousands of iterations. If training goes well, the arms race drives both networks toward a Nash equilibrium: G produces outputs indistinguishable from real data and D outputs 0.5 for everything. If training goes poorly, the generator may mode-collapse (producing only a few safe outputs) or gradients may vanish (discriminator too strong). Monitoring sample diversity and discriminator scores is essential.
Mode collapse happens because the generator finds a "sweet spot" that consistently fools the current discriminator and exploits it, rather than learning the full data distribution. The minimax game does not directly incentivize diversity.
Figure
A gallery of generated faces that all look nearly identical -- same pose, same expression, same hair -- despite being generated from different random noise inputs. The generator collapsed to a single mode.
Mode collapse: the generator only produces one type of output
When the discriminator becomes too powerful too quickly, it assigns near-zero probability to all generator outputs. The generator's loss becomes flat -- the gradient signal vanishes. The generator is stuck producing noise because it receives no useful feedback about how to improve.
Unlike standard optimization where loss monotonically decreases, GAN training is a game between two players. The loss can oscillate indefinitely without converging. The discriminator improves, then the generator improves, then the discriminator's previous improvements become insufficient, and so on in circles.
Replaces the binary cross-entropy loss with the Wasserstein distance (Earth Mover's distance), which provides smooth, non-vanishing gradients even when the discriminator is strong.
Constrains the discriminator's Lipschitz constant by normalizing weights by their spectral norm (largest singular value). This prevents the discriminator from changing too rapidly, stabilizing the game.
Start by generating tiny 4x4 images. Once training stabilizes, add layers to both G and D to generate 8x8, then 16x16, and so on up to 1024x1024. Each stage learns to add finer details. This was the key insight behind ProGAN and its successor StyleGAN.
By 2020, GANs were the undisputed champions of image generation. StyleGAN2 produced photorealistic faces at 1024x1024. Then diffusion models arrived and systematically overtook GANs:
Dimension
GANs
Diffusion Models
Image quality
Excellent (sharp)
Excellent (and more diverse)
Training stability
Fragile, many failure modes
Stable, straightforward
Mode coverage
Prone to mode collapse
Full distribution coverage
Controllability
StyleGAN: good. Others: limited
Classifier-free guidance: excellent
Speed
Fast (single forward pass)
Slow (many denoising steps)
Theory
Minimax game (tricky)
Variational bound (clean)
GANs are not dead -- they remain important for real-time applications (super-resolution, style transfer, video synthesis) where single-pass generation speed matters. But for general image generation, diffusion models have won.
GANs learn through adversarial competition. The generator creates fakes, the discriminator detects them, and the competitive pressure drives both to improve until the generator produces convincing samples
Mode collapse is GANs' signature failure mode. The generator may learn to produce only a few realistic samples that fool the discriminator, ignoring the full diversity of the real data distribution
GAN training is inherently unstable. The minimax game can oscillate, diverge, or collapse; techniques like Wasserstein loss, spectral normalization, and progressive growing address these issues but do not fully solve them
StyleGAN introduced revolutionary control over generation. By injecting style information at different layers, StyleGAN enables fine-grained control over generated images (pose, identity, lighting) at different scales
In the GAN minimax game, what does the discriminator try to maximize?
You now understand the adversarial game that powers GANs, the training instabilities that plagued the field for years, and the architectural innovations that tamed them. Next up: the model family that dethroned GANs -- Diffusion Models. We start with the forward process: systematically destroying images with noise.