Generative Adversarial Networks (GAN) – Concept and Applications
Two networks locked in a game — one forging fakes, one hunting them down — until the fakes win
Two networks locked in a game — one forging fakes, one hunting them down — until the fakes win
A GAN trains two neural networks against each other — a Generator that tries to forge realistic fake data from random noise, and a Discriminator that tries to catch the fakes — until the Generator gets good enough that its fakes fool the Discriminator consistently.
GANs produce some of the sharpest, most realistic generated images of any family (faces, art, photo upscaling) and are the basis for a huge range of production tools — face generation, style transfer, deepfakes (and deepfake detection), data augmentation for training other models. Understanding the adversarial game is also the foundation for every GAN variant covered later (conditional GAN, StyleGAN).
Yaha samajhna zaroori hai ki a GAN isn't one model, it's a contest between two. The Generator
G is like a forger trying to paint fake currency; the Discriminator D is like a detective trying
to spot the fakes. At the start, the forger is terrible and the detective catches everything easily.
But every round, the forger learns from what got caught and improves, while the detective also keeps
learning to catch the increasingly good fakes. Played long enough, the forger's fakes become
indistinguishable from the real thing — at that point D is reduced to guessing, essentially 50/50.
Formally, this is a minimax game: G tries to minimize the chance D correctly spots a fake,
D tries to maximize its accuracy at telling real from fake. Both networks improve only because
the other is improving — that's what "adversarial" means here.
Referring to the diagram above, one full workflow loop:
z (sampled from a simple distribution, e.g.
N(0, I)) and transforms it into a synthetic sample G(z) — a fake image, say.G(z)), without being told which is which, and outputs a probability that each input is
real.D's error on telling real from fake is used to update D's weights — making it a better
detective.G's error — specifically, how many of its fakes D didn't get fooled by — is used to update
G's weights (via gradients flowing back through D into G) — making it a better forger.G's samples are
realistic enough that D can't do better than random guessing.Only G is used at inference time — once trained, you just feed it fresh noise z and it outputs new
synthetic samples; D is discarded (or repurposed, e.g. as a feature extractor).
Value function (the minimax game):
min_G max_D V(D,G) = 𝔼_{x∼p_data}[log D(x)] + 𝔼_{z∼p_z}[log(1 − D(G(z)))]
Here D(x) is the Discriminator's estimated probability that real sample x is real, D(G(z)) is
its estimated probability that the Generator's fake G(z) is real, p_data is the true data
distribution, and p_z is the simple noise distribution (e.g. standard normal) that z is sampled
from.
log D(x) + log(1 − D(G(z))) — wants D(x) close to 1 (correctly
calls real data real) and D(G(z)) close to 0 (correctly calls fakes fake).log(1 − D(G(z))) — wants D(G(z)) close to 1 (to
fool D). The non-saturating alternative used in practice, and why, is covered in the training
topic later.Say in one iteration, the Discriminator scores a real image x as D(x) = 0.9 (correctly confident
it's real — illustrative value) and scores a fresh fake G(z) as D(G(z)) = 0.2 (correctly leaning
toward "fake"). D is doing well here, so its gradient update reinforces its current weights
slightly. Meanwhile G's objective pushes it to change G(z) so that next time, D(G(z)) lands
closer to 1 instead of 0.2 — i.e. G adjusts to produce something that looks more convincingly real
next round. Over thousands of such rounds, D(G(z)) creeps from near 0 up toward ~0.5 as the fakes
get harder to distinguish from real data.
z as input; it
learns to produce realistic output purely from the gradient signal D sends back, never from
looking at real samples itself.D can't tell real from fake better than chance (~0.5) — it does not
mean the loss values go to zero the way a normal supervised loss would.V(D,G) is one
shared expression that D maximizes and G minimizes; they aren't two unrelated loss formulas.A GAN is a forger-vs-detective game played as a minimax objective — the Generator never sees real data, it only ever learns from how well it fools the Discriminator.