Syllabus Lesson 177 of 246 · Module 16: Two networks in a game (GANs, optional)
Module 16: Two networks in a game (GANs, optional)

The game on eight blobs

Why it matters Pictures hide what a GAN does wrong. Points in 2D do not: you can see at once which parts of the data the generator found and which it missed.

The real data: 8 tight blobs on a circle. A good generator puts points on all 8 blobs, about equally. The judge, ganlab.coverage(points), gives two numbers: blobs covered (a blob counts when it gets more than 2% of the points) and quality (the share of points that land on any blob).

Watch the scene: real blobs, then where a trained generator's points land, then a generator that collapsed.

One training step has two halves:

  1. D's turn. A batch of real points (ganlab.ring(128, rng)) and a batch of fakes. Take the fakes as plain numbers (.data) so D's step does not reach into G. Loss = BCE(score(real), 1) + BCE(score(fake), 0). Step D.
  2. G's turn. New noise, generate, score with D, loss = BCE(score, 1): the non-saturating loss. Step G. This backward pass also filled D's gradients; set them back to None, or they leak into D's next step.

GANs use Adam with its first beta at 0.5 (the house Adam takes b1). The course measured why: with the default 0.9 the same GAN covered between 1 and 7 blobs over 5 seeds, with 0.5 it covered 7 or 8.

Words and symbols in this lesson
GAN
generative adversarial network: a generator and a discriminator trained against each other
generator (G)
the network that turns noise into a sample
saturating loss
G minimises log(1 - D(G(z))); its slope is about 0 once D is sure, so G stops learning
non-saturating loss
G minimises -log D(G(z)); same goal, a full push even when D is sure
blobs covered, quality
the ring judge: blobs with more than 2% of the points, and the share of points on a blob
Your turn

Write the body of the training loop: 2000 steps (about 4 seconds in the browser). Pass with at least 7 blobs covered and quality at least 0.5. Write the loop yourself: ganlab.train is off limits here.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.