15.1 Introduction to GANs
A generator and a discriminator playing a two-player game.
These notes walk through the lecture slides. The original deck is unchanged; use (slides) on the course hub if you want that PDF.
Figures and notes follow Géron, Hands-On Machine Learning; Deisenroth, Faisal, and Ong, Mathematics for Machine Learning; and Theodoridis, Machine Learning: A Bayesian and Optimization Perspective.
1. Generative adversarial networks
Generative adversarial networks (GANs) are from Goodfellow et al., 2014. The idea caught on immediately; stable training took years.
A GAN is two neural nets.

2. Applications
| Use | Sketch |
|---|---|
| Image generation and editing | Faces, objects, landscapes; inpainting missing patches. |
| Data augmentation | Extra synthetic rows when labels are expensive. |
| Text-to-image | A sentence in, a matching scene out. |
| Style transfer | Copy the look of one image onto another. |
| Molecular generation | New drug-like or materials structures. |
| Anomaly detection | Train on normal data; flag points far from that law. |
| Domain adaptation | Map a source domain onto a target domain and keep the meaning. |
3. Generator
The generator takes a random draw (usually Gaussian) and emits a sample, often an image.
Treat that draw as a latent coding. Functionally this is the decoder of a VAE: Gaussian noise in, a new image out. The training rule is different.
Write for the noise and
for a fake sample with the same dimension as a real observation , . are the generator weights. Training aims to make the fakes statistically indistinguishable from the reals.
4. Discriminator
The discriminator sees either a fake from or a real training image, and guesses which. It is a binary classifier. On input it returns
the probability that is real. Then is the probability it is fake. are the discriminator weights.
5. Training
Opposite goals. The discriminator wants to tell fakes from reals. The generator wants fakes that fool the discriminator. You cannot train this as one ordinary net. Each iteration has two phases.
- Train the discriminator. A batch of reals, plus as many fakes from the current generator. Labels: 0 fake, 1 real. One binary-cross-entropy step. Backprop updates only .
- Train the generator. A fresh batch of fakes. No reals. Every label is 1 (real): you want the discriminator to be wrong. Freeze ; backprop updates only .
6. The cost function
A two-player min-max game:
is the real-data law. With held fixed, the discriminator is trained so that is large on reals and is large on fakes.
7. Algorithm
Initialize and . Minibatch size . Let be the number of discriminator steps per generator step ( in the original paper).
While and have not converged:
- For :
- Sample , , from .
- Sample , , from .
- Ascend on using
- Then sample a new , , from and descend on using
Practice
-
What two networks are playing the GAN game, and what does each want?
-
In the generator step, why are all labels set to 1 (real), and which weights stay frozen?
-
With held fixed, what is the discriminator maximizing on real and on fake ?