Modern AI Engineering

Lesson 16.5 · 27 min · video lesson

GANs: A Generator and Discriminator in Constant Competition

What happens if we train one network to forge images and a second network to catch the forgeries — and let them compete until the forger wins?

In short: A Generative Adversarial Network (GAN) trains two networks against each other: a generator that turns random noise into fake samples, and a discriminator that tries to tell real samples from fakes. Each improves by exploiting the other's weaknesses, and at the ideal end point the fakes are indistinguishable from real data. GANs generate sharp images in a single fast pass, but training is a delicate balancing act that can oscillate or collapse to a few repeated outputs.

What you will learn

  • What is a Generative Adversarial Network (GAN)?
  • The two players: Generator vs Discriminator
  • The counterfeiter vs police analogy
  • The adversarial training loop
  • The loss function and the minimax game in simple words
  • A tiny PyTorch-style code sketch
  • The mode collapse problem
  • Training stability
  • Types of GANs (DCGAN, Conditional GAN, StyleGAN, CycleGAN)
  • Real-world applications of GANs

In this lesson

  1. What is a Generative Adversarial Network (GAN)?
  2. The two players: generator vs discriminator
  3. The counterfeiter vs police analogy
  4. The adversarial training loop
  5. The loss function and the minimax game in simple words
  6. A tiny PyTorch-style code sketch (and a runnable numpy version)
  7. The mode collapse problem
  8. Training stability
  9. Types of GANs (DCGAN, Conditional GAN, StyleGAN, CycleGAN)
  10. Real-world applications of GANs
  11. Worked example, step by step
  12. Practice: try it yourself

Key terms in this lesson

Generator
The network that maps random noise to synthetic samples.
Discriminator
The network that outputs the probability that a sample is real.
Minimax game
A two-player objective that one player maximises and the other minimises.
Non-saturating loss
The generator objective 'maximise log D(G(z))', which avoids vanishing gradients early on.
Mode collapse
When a generator covers only a few modes of the data, producing low-variety outputs.
Latent space
The space of noise vectors z that the generator maps to outputs.
Cycle-consistency loss
A loss requiring that translating A → B → A returns the original input.

This lesson is part of the Generative AI Engineering and Complete AI Engineer tracks. See plans and pricing to open the full lesson, its video, labs and quiz, or try the free lesson first (free account needed).

← 16.4 Diffusion Models: Iterative Denoising to Generate Images · 16.6 Variational Autoencoders: Learning a Compressed Latent Space →