🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
Search courses…
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

GANs — Generative Adversarial Networks Complete Guide

Deep LearningGANs🟢 Free Lesson

Advertisement

Deep Learning

Generative Adversarial Networks — AI Creates Art, Faces, and More

Learn how GANs use adversarial training to generate realistic synthetic data from noise.

  • Adversarial training — generator vs. discriminator dynamic
  • Image synthesis — create photorealistic faces and art
  • Training dynamics — Nash equilibrium, mode collapse, and convergence

Creativity is intelligence having fun.

GANs — Generative Adversarial Networks

GANs (Goodfellow et al., 2014) learn to generate data by framing generation as a two-player minimax game between a generator and discriminator .


GAN Architecture

Noisez ~ p(z)128-512 dimGeneratorG(z)DeConv layersBN + ReLU → TanhG(z)FakeImagegeneratedDiscriminatorD(x)Conv layersLeakyReLU + BN→ SigmoidReal or Fake?RealImagefrom datasetOutputD(x) ∈ [0,1]Real → 1Fake → 0Training DynamicsGenerator:Learns to fool D. Gradient from D→G: "make outputs more realistic"Discriminator:Learns to classify real vs fake. Gradient: "distinguish better"Equilibrium:D(x) = 0.5 ∀x — G generates perfect samples, D cannot distinguish

How GAN training works: The diagram shows the two-player game at the heart of GANs. The Generator (green, left) takes random noise z (a 128-512 dimensional vector sampled from a normal distribution) and transforms it through deconvolution layers into a fake image. The Discriminator (yellow, right) receives both real images from the dataset and fake images from the generator, outputting a probability D(x) ∈ [0,1] — real images should score near 1, fake near 0. The training dynamics box at the bottom explains the adversarial loop: the generator learns from gradients flowing back through the discriminator ("make more realistic images"), while the discriminator learns to distinguish better ("catch the fakes"). At equilibrium, the generator produces perfect samples and the discriminator outputs 0.5 for everything — it can no longer tell real from fake. This minimax game drives both networks to improve simultaneously.


Loss Functions


Training Process

GAN Training LoopStep 1: Train Discriminator (k steps)1. Sample real batch {x₁,...,x_B} ~ pdata2. Sample noise {z₁,...,z_B} ~ pz3. Generate fakes: x̃i = G(zi)4. Maximize: LD = -Σ[log D(xi) + log(1-D(G(zi)))]5. Update θD ← θD - α·∇LDUsually k=1 step (but can be more)Step 2: Train Generator (1 step)1. Sample noise {z₁,...,z_B} ~ pz2. Minimize: LG = -Σ log D(G(zi))3. Update θG ← θG - α·∇LG (through D)D parameters frozen during G updateConvergence:Epoch 1: G generates noise, D easily classifies → LD ≈ 0, LG ≈ ∞Epoch N: G improves, D struggles → LD ≈ log 2, LG ≈ -log 2 → Nash equilibrium at D(x) = 0.5

Mode Collapse

Mode CollapseGood: pg ≈ pdataMode 1Mode 2Bad: Mode CollapseMode 1Mode 2All here!No CollapseMode 1One mode onlyMode collapse:G learns to produce only 1-2 outputs that fool D. Common failure mode.Solutions:WGAN loss, unrolled GAN, minibatch discrimination, spectral normalization

DCGAN Architecture


GAN Variants

GAN Family TreeGAN2014Minimax lossDCGAN2015Conv architectureWGAN2017Wasserstein lossStyleGAN2018Style transferProGAN2017Progressive growcGANConditionalLabel → imagePix2Pix2016Paired translationCycleGAN2017Unpaired translationBigGAN2018Large scale, class-conditionalStyleGAN220201024×1024 facesGANs are being largely replaced by diffusion models (DALL-E 2, Stable Diffusion, Imagen) for image generation, but remain relevant for style transfer and real-time applications.

WGAN (Wasserstein GAN)


Key Takeaways


What to Learn Next

-> Autoencoders Learn about compressed representations.

-> Variational Autoencoders Generate data with probabilistic models.

-> Diffusion Models Deep Dive Master modern generative AI techniques.

-> Neural Networks Understand the foundation of deep learning.

-> CNNs Learn the convolutional architectures used in GANs.

-> Training Deep Networks Master training techniques for unstable models.

Need Expert Machine Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement