GAN, a forger against a detective


Real data
Train
The two players are both small neural networks. Each hidden layer has 32 neurons; 8 are drawn. The network that is learning lights up.
real dots   fake dots from the forger   background: what the detective thinks — “real” “can't tell” “fake”
The detective's average “real” score for real dots and fake dots, after every training step. The dashed line is 0.5: “can't tell.”

The whole idea.
A GAN (Generative Adversarial Network) is two networks playing a game. The forger (the generator) takes 2 random numbers and turns them into a dot. The detective (the discriminator) looks at a dot and gives a score from 0 to 1: how sure it is that the dot is real.

They take turns. The detective learns to give real dots a high score and fake dots a low one. Then the forger learns to move its dots to where the detective says “real.” The forger never sees a real dot. All it gets is the detective’s opinion.

When the game works, the fake dots sit on the real shape, the detective gives everything about 0.5, and the background turns almost white: it cannot tell real from fake any more.

A picture GAN plays the same game. Each “dot” is a whole picture, the forger turns random numbers into a picture, and the detective looks at pictures.

Things worth trying:
1. Ring, then Run both. Over 20 runs, 19 had at least 85% of the fake dots on the ring after 1,750 rounds — about 10 seconds here.

2. Start over, then Detective ×10 five times, with no forger. The detective learns to tell them apart: over 20 runs it gave real dots 0.60 and fake dots 0.36 on average. Now press Forger ×10 once: the fakes jump to 0.55. Fooling a detective that has stopped learning is easy.

3. Start over, then Forger ×10 ten times, with no detective. The forger chases a detective that never learns. Its “real” score climbs (0.85 on average), but only 3% of its dots land on the ring, and in 16 of 20 runs more than half of them flew off the picture. A forger is only as good as its detective.

4. Eight blobs, then Run both twice (4,000 rounds). Over 20 runs of 4,000 rounds, 16 found all 8 blobs, and 4 kept missing one. This is a small case of mode collapse: the forger makes only some kinds of real data and skips the rest. In a face GAN it looks like a forger that draws only a few kinds of faces.