4.5.9Generative Models

DCGAN, WGAN, StyleGAN

2,752 words13 min readdifficulty · medium

Overview

These three architectures represent evolutionary milestones in GAN training stability and image quality. Each solved critical problems that plagued vanilla GANs: DCGAN established architectural guidelines for stable training, WGAN fixed the broken loss function mathematically, and StyleGAN revolutionized fine-grained control over generated features.

Figure — DCGAN, WGAN, StyleGAN

DCGAN (Deep Convolutional GAN)

WHY each guideline matters:

  1. Strided convolutions: Letting the network learn its own spatial downsampling/upsampling is more flexible than fixed pooling. In generator, transposed convolutions upsample feature maps (e.g., 4×4 → 8×8 → 16×16 → ... → 64×64).

  2. Batch normalization: Normalizes layer inputs to zero mean, unit variance. This prevents gradient explosion/vanishing by keeping activations in reasonable ranges. Why not on input/output? Input is already normalized images, output needs full color range.

  3. No FC layers: Fully connected layers lose spatial structure. Keeping everything convolutional preserves locality—nearby pixels influence each other, not random global mixing.

  4. Activation choices: ReLU in generator encourages sparse, efficient representations. LeakyReLU in discriminator prevents "dying ReLU" problem (gradients flow even for negative inputs). Tanh output maps to [-1, 1] matching normalized image range.

  5. Adam hyperparameters: Standard Adam (β₁=0.9) caused training oscillations. Lower momentum (β₁=0.5) reduces oscillation in adversarial setting.


WGAN (Wasserstein GAN)

Deriving the trainable form:

By Kantorovich-Rubinstein duality:

W(Pr,Pg)=supfL1ExPr[f(x)]ExPg[f(x)]W(P_r, P_g) = \sup_{\|f\|_L \leq 1} \mathbb{E}_{x \sim P_r}[f(x)] - \mathbb{E}_{x \sim P_g}[f(x)]

Where fL1\|f\|_L \leq 1 means ff is 1-Lipschitz continuous: f(x1)f(x2)x1x2|f(x_1) - f(x_2)| \leq |x_1 - x_2| for all x1,x2x_1, x_2.

WHY this helps: We can approximate this by training a neural network fwf_w (the "critic", replacing discriminator) to maximize:

Lcritic=ExPr[fw(x)]Ezp(z)[fw(Gθ(z))]L_{\text{critic}} = \mathbb{E}_{x \sim P_r}[f_w(x)] - \mathbb{E}_{z \sim p(z)}[f_w(G_\theta(z))]

Subject to fwf_w being 1-Lipschitz. Generator minimizes the negative:

Lgen=Ezp(z)[fw(Gθ(z))]L_{\text{gen}} = -\mathbb{E}_{z \sim p(z)}[f_w(G_\theta(z))]

WHY Lipschitz matters: Without the constraint, fwf_w could grow unbounded (just multiply weights by 1000), making loss meaningless. 1-Lipschitz keeps the critic "bounded" and forces it to learn real structure.


WGAN-GP (Gradient Penalty)


StyleGAN

Concept Map

stabilized by

fixes loss math

adds style control

defines

includes

includes

includes

includes

enables

uses

prevents

achieves

Vanilla GAN unstable

DCGAN

WGAN

StyleGAN

Architectural Guidelines

Strided Convolutions

Batch Normalization

ReLU and LeakyReLU

Adam lr 0.0002 b1 0.5

Wasserstein Loss

Fine-grained Feature Control

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, GAN training shuru mein ek nightmare tha—mode collapse, gradients vanish ho jaate the, aur hyperparameters ko tune karna almost impossible lagta tha. Yeh teen architectures—DCGAN, WGAN, aur StyleGAN—basically evolution ke milestones hain jinhone in problems ko step-by-step solve kiya. DCGAN ne prove kiya ki agar aap sahi building blocks use karo—matlab convolutions, batch normalization, aur sahi activation functions—toh training stable ho jaati hai, bhale hi underlying loss function thoda shaky ho. Ise aise samjho jaise ghar banate waqt sahi material use karna, taaki structure collapse na kare.

Ab DCGAN ki core intuition yeh hai ki har architectural choice ka ek solid reason hai. Strided convolutions network ko khud spatial upsampling seekhne dete hain (fixed pooling se zyaada flexible), batch norm activations ko reasonable range mein rakhta hai taaki gradient explode ya vanish na ho, aur fully connected layers hataane se spatial structure preserve rehti hai—nearby pixels ek doosre ko influence karte hain, random global mixing nahi hoti. Generator basically ek chhote 4×4 "seed" se shuru hota hai aur transpose convolutions ke through resolution ko double karta jaata hai (4×4 → 8×8 → ... → 64×64), saath hi channels halve karte jaata hai. Isse coarse structure dheere-dheere fine details mein refine hota hai.

Yeh cheez matter isliye karti hai kyunki DCGAN ne foundation set kiya jispe pura modern generative AI khada hai—aaj jo realistic faces, art, aur images generate hoti hain, unki root yahin hai. Agar aap intuition samajh loge ki kyun batch norm input/output pe nahi lagta, ya kyun β₁=0.5 use karte hain oscillation kam karne ke liye, toh aap sirf formula ratne se aage badhoge—aap actually GAN ka behavior predict aur debug kar paoge. Yeh understanding aage WGAN aur StyleGAN jaise advanced models samajhne ke liye strong base ban jaati hai.

Go deeper — visual, from zero

Test yourself — Generative Models