Generator vs Discriminator: The Game
Two networks competing to improve.
Generator vs Discriminator: The Game is a free Deep Learning Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Deep Learning Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Two Networks, One Game
A GAN is two neural networks playing a game: one invents fake data, the other tries to catch it. Their rivalry is what makes both improve. 🎭
Meet the Generator
The generator starts with random noise and shapes it into something that looks like real data, such as a fake face. It never sees the real images directly.
Meet the Discriminator
The discriminator is a judge. It looks at a sample and outputs one number: how likely it thinks that sample is real rather than fake.
Noise In, Image Out
You feed the generator a vector of random numbers called the latent vector. Different vectors produce different outputs, so noise becomes the seed of creativity.
z = torch.randn(1, 100)
fake = generator(z)A Forger and a Detective
Think of a forger making fake bills and a detective spotting them. Each one pushes the other to get sharper. That tug-of-war is the heart of a GAN.
Real or Fake Label
The discriminator trains on labels: real images get 1 and generated images get 0. It learns to tell the two apart with confidence.
real_label = 1.0
fake_label = 0.0The Generator's Goal
The generator wins when the discriminator labels its fakes as real. So its goal is to fool the judge, not to copy any single image exactly.
Adversarial Means Opposed
Their objectives are opposite, which is why we call it adversarial. The discriminator wants to be right; the generator wants it to be wrong.
Improving Together
As the discriminator gets pickier, the generator must make better fakes to keep fooling it. This feedback loop lifts both networks over time.
Two Optimizers
Because the players have separate goals, each network gets its own optimizer and updates on its own turn during training.
opt_g = torch.optim.Adam(G.parameters())
opt_d = torch.optim.Adam(D.parameters())The Goal: Indistinguishable
Training ideally ends when the discriminator can only guess, near 50 percent. At that point the fakes are practically indistinguishable from real data.
Quick Check
Let's make sure the roles are clear.
Recap: The GAN Game
You met both players: a generator that forges data from noise and a discriminator that judges it. Their rivalry drives both to improve. 🎉
Frequently asked questions
Is the “Generator vs Discriminator: The Game” lesson free?
Yes — the full text of “Generator vs Discriminator: The Game” is free to read here on the web, and the Deep Learning Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Deep Learning Academy course, upgrade to CoddyKit PRO.
What will I learn in “Generator vs Discriminator: The Game”?
Two networks competing to improve. You practise Deep Learning Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Deep Learning Academy?
No prior experience is required. Deep Learning Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Generator vs Discriminator: The Game” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Deep Learning Academy lesson?
Yes. Every Deep Learning Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Generator vs Discriminator: The Game
- The Adversarial Loss
- Build a DCGAN
- Mode Collapse & Stabilizing Tricks