7 routes42 sections324 units

Unit 6.4 · about 4 h

210 / 324

GAN objectives, alternating updates and mode collapse

GANs are the adversarial counterpoint to likelihood training: no density, a learned loss, and failures that look like good samples. The minimax argument explains why.

  • derive
  • explain

You can now

  • Derive the minimax losses, the optimal discriminator, and the Jensen-Shannon form of the generator signal.
  • Run alternating D-then-G updates with the non-saturating generator loss on a small GAN.
  • Distinguish mode dropping from mode collapse and name the imbalance that causes each.

Covers

  • GAN minimax objectives and alternating updates
  • Generator-discriminator balance and mode collapse

Study, in this order

4 steps

  1. Minimax, optimal discriminator and the Jensen-Shannon split
    Understanding Deep Learning - generative models

    Sections 15.1 to 15.2.2 with Equations 15.2 to 15.9 (pp. 276 to 283)

  2. Wasserstein, DCGAN recipe and collapse
    Understanding Deep Learning - generative models

    Sections 15.2.3 to 15.2.6 on Wasserstein (pp. 284 to 286); Section 15.1.3 DCGAN recipe and Section 15.1.4 with Figure 15.5 on mode dropping and collapse (pp. 279 to 281)

    Depth · Skip Sections 15.3 to 15.6 here: progressive growing, conditional GANs, translation and StyleGAN are later material.

  3. Basic GAN on a 2D Gaussian
    D2L - GAN and DCGAN

    Generate Some Real Data, Generator, Discriminator and Training: 2D Gaussian with A=[[1,2],[-0.1,0.5]] and b=[1,2], linear generator, 3-layer Tanh discriminator, batch size 8, \(D\) updated before \(G\) each iteration

  4. DCGAN blocks and Pokemon training
    D2L - GAN and DCGAN

    The Generator with G_block and the 100-dim latent to 64 by 64 map; Discriminator with D_block and leaky ReLU 0.2; Training with Adam beta1 0.5

Focus on

  • Equations 15.2 to 15.5 turn binary cross-entropy into a minimax game. The practical generator loss is the non-saturating \(-\log D(G(z))\) (label flipped to 1), because the \(\max \log(1 - D)\) form saturates when \(D\) is confident.
  • Section 15.2.1 shows the optimal discriminator is \(\Pr(x)/[\Pr(x) + \Pr(\text{fake})]\), and the loss becomes a Jensen-Shannon divergence split into quality and coverage terms. The book notes that the real-data term of Eq 15.6 does not involve the generator, so nothing directly rewards it for covering missed modes; it calls this the putative reason for mode dropping.
  • Section 15.1.4 separates the failures: mode dropping generates a realistic subset (no beards), while collapse maps most \(z\) to one or few points and ignores \(z\). Figure 15.5 and the Notes diversity paragraph make this concrete.
  • The DCGAN recipe is strided convolutions, BatchNorm in both nets, leaky ReLU in \(D\) and Adam with beta1 0.5. D2L updates \(D\) first each iteration with detached fakes so no gradient reaches \(G\) through the \(D\) step.

Reproduce closed-book

Closed-book, write the two losses of Equation 15.5 and the non-saturating generator loss. Then run the D2L basic GAN for 20 epochs at lr_D 0.05 and lr_G 0.005 and watch the discriminator loss move toward about 0.69 (\(\log 2\), the value when \(D\) outputs 0.5 everywhere) as the fake scatter covers the real Gaussian.

Traps

  • Forgetting detach on fake_X in the \(D\) step. The \(D\) loss then backpropagates into \(G\): wasted compute, and if \(G\)'s gradients are not zeroed before its own step, \(G\) also moves in the direction that helps \(D\).
  • Following the DCGAN summary line about BatchNorm literally. The shipped D_block applies BatchNorm in every block including the first, while the paper recipe uses no norm on the discriminator input. Implement the paper variant and note the difference.
  • Reading \(D\) accuracy 0.5 as proof of distributional match. A finite-capacity \(D\) reaches chance on a mode-dropped generator too; the Notes duplicate test shows support can be far smaller than the training set.

Practice

D2L basic GAN: alternating training on the 2D Gaussian

Training with update_D and update_G: batch size 8, latent dim 2, 20 epochs; confirm \(D\) runs before \(G\) and fakes use detach

Plot real versus fake scatter at epochs 1, 5 and 20, and add a discriminator-accuracy printout. State the epoch where accuracy first nears 0.5, and remember that chance accuracy does not prove the distributions match.

UDL Problem 15.4: divergences for shifted uniforms

Problem 15.4 (p. 303): KL, reverse KL, JS and Wasserstein for uniform \([0, 1]\) versus \([a, a+1]\) over \(a\) in \([-3, 3]\)

Do it on paper: KL is infinite for any nonzero \(a\), JS is \(|a| \log 2\) up to 1 and \(\log 2\) after, W1 is \(|a|\). This is the disjoint-support case Wasserstein was introduced for.

Self-test

  1. Write the two alternating losses and the update order.

  2. Why can the generator ignore coverage, according to Section 15.2.1?

  3. Distinguish mode dropping from mode collapse.

  4. For uniform \([0, 1]\) versus \([a, a+1]\) with \(a = 2\), give KL, JS and W1.

Completion criterion

Stop when

You derive the JS split without notes, your D2L run shows \(D\)-first updates with detached fakes, and you solve Problem 15.4 for \(a = 0\), 0.5 and 2.

Mark passed, then open 6.5 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

  • Understanding Deep Learning - generative models
    Simon J. D. Princeprimarytheory
    Read Chapter 14 for evaluation limits, 15 for GANs, 17 for VAE and ELBO, and 18 for diffusion. Read Chapter 16 only for flow recognition. Use notebooks 17.1-17.3 and 18.1-18.4 as mathematical and visual practice.
  • D2L - GAN and DCGAN
    D2L authorssupportimplementation
    Use gan.md and dcgan.md for one bounded adversarial exposure. The required implementation remains a small VAE with separate reconstruction and KL terms on a two-dimensional mixture or binarized MNIST subset.

Also in this section

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels