AI Foundations ← pitcsolutions.com All lessons

Lesson 11 of 13 in Generative models, about 8 minutes

Generative Adversarial Networks (GANs)

One network creates fakes, another tries to catch them. The competition makes both brilliant.

By the end of this lesson you will be able to

  • name the two parts of a GAN and what each one does
  • explain how competition makes both parts improve
  • list where GANs are used, and why they are hard to train
The counterfeiter and the police officer

One person makes fake currency. Another is a police officer checking notes. Every time the officer catches a fake, the counterfeiter learns and improves. Every time a fake slips through, the officer gets sharper. Both keep improving because they compete. That is how a GAN works.

GAN = ā€œOne AI creates fake things, another AI checks if they look real.ā€ Both improve by competing.

The two parts of a GAN

1. Generator: the faker šŸŽØ

Job: create fake data that looks real: a face, a voice, an image, handwriting.

It starts from random noise, so at first its output is terrible: blurry faces, weird shapes, nonsense.

2. Discriminator: the judge šŸ”

Job: decide whether data is real or fake.

It sees real images from the dataset and fake images from the generator, and says ā€œthis is realā€ or ā€œthis is fakeā€.

GAN diagram: random noise goes into the generator, which produces a fake image. The discriminator receives both the fake image and real images from the dataset and outputs real or fake. Feedback flows back to both networks. Random noise Generatorthe faker Fake image Realimages Discriminatorthe judge Real orfake? feedback: ā€œyou were caught, improveā€
The generator never sees real images directly. It learns only from the discriminator's verdicts.

How training happens: a game

  1. Step 1

    The generator creates a fake image, for example a fake cat.

  2. Step 2

    The discriminator compares it with real cat images and says: ā€œThis looks fake.ā€

  3. Step 3

    The generator learns from the mistake and improves its next fake.

  4. Step 4

    The discriminator also gets smarter and detects better fakes.

Generator gets…Discriminator gets…
Better at making fakesBetter at detecting fakes
Learns realismLearns to spot errors

This competition repeats thousands or millions of times. Eventually the fakes become so realistic that the discriminator can no longer tell the difference, which means the generator has become very good.

A student example

A student forges a teacher's signature. The teacher says ā€œFake.ā€ The student improves; the teacher becomes more careful. After many tries, the signature is almost identical. That learning competition is a GAN.

Example: faces that never existed

Train a GAN on thousands of real human faces. The generator learns eye placement, skin texture, nose shapes, lighting and hair patterns. After training it can generate completely new faces of people who have never existed.

Important

The generator does not memorise exact images. It learns the patterns of real data: how eyes are placed, how shadows fall, how textures look.

Where GANs are used

  1. Image generation

    Realistic synthetic photos.

  2. AI art

    Creative image synthesis.

  3. Face ageing

    Young → old face conversion.

  4. Super-resolution

    Sharpen blurry, low-resolution images.

  5. Medical imaging

    Generate extra training samples where real data is scarce.

  6. Deepfakes

    Fake videos and voices, a serious misuse risk.

Use responsibly

The same technology that restores old photos can produce deepfakes used for fraud and misinformation. Always consider consent and disclose AI-generated media.

The main weakness: GANs are hard to train

Getting a GAN to train properly is hard even for experienced ML engineers. That's one reason many modern image generators use diffusion models instead.

A simple technical view

Generator's goal

Minimise how fake its output looks to the discriminator.

Discriminator's goal

Maximise how correctly it detects fakes.

Mathematically they are opponents, which is why it's called a Generative Adversarial Network. ā€œAdversarialā€ means competing or opposing.

Key takeaways

  • A GAN has a generator (the faker) and a discriminator (the judge).
  • They improve by competing, until fakes become indistinguishable from real data.
  • GANs produce sharp, realistic images but are notoriously hard to train.

Check your understanding

1. What does the generator start from?

The generator transforms random noise into data; it never copies real images directly.

2. When is a GAN's training considered successful?

If the judge is reduced to guessing, the generator's fakes are realistic.

3. What is ā€œmode collapseā€?

It's a classic GAN failure: variety disappears because one trick keeps working.