Deep Learning1 code example
⚡ +100 XP

Generative Adversarial Networks (GANs)

1

GAN Concept

A GAN consists of two neural networks competing in a minimax game: Generator G: Takes random noise z → generates fake data G(z) Discriminator D: Takes real or fake data → outputs probability of being real MinMax objective: min_G max_D E[log D(x)] + E[log(1 − D(G(z)))] D tries to maximize (correctly classify real vs fake) G tries to minimize (fool D into thinking fakes are real)

2

Training Challenges

Mode Collapse — Generator produces only a few types of outputs, ignoring diversity. Vanishing Gradients — When D is too good, gradients for G go to zero. Training Instability — Loss oscillates, never converges cleanly. Fixes: • Wasserstein GAN (WGAN) — uses Wasserstein distance instead of JS divergence. More stable. • Spectral Normalization — constrains D's Lipschitz constant • Progressive Growing — train at low resolution first, gradually increase

3

Famous GAN Variants

DCGAN — Deep Convolutional GAN. Replaced FC layers with convolutions for image synthesis. StyleGAN2 — NVIDIA. Photo-realistic face generation. Style-based generator. Conditional GAN (cGAN) — Generate images conditioned on a class label. CycleGAN — Image-to-image translation without paired data (horse↔zebra). Pix2Pix — Paired image translation (sketch→photo, aerial→map).

4

DCGAN from Scratch

💡

Use betas=(0.5, 0.999) for GAN training — empirically found to stabilize training vs the default (0.9, 0.999).

Finished reading? Mark it complete to earn your XP.