Generative Adversarial Networks (GAN)

Definition:

GAN Objective

minGmaxD  Expdata[logD(x)]+Ezp(z)[log(1D(G(z)))]\min_G \max_D \; \mathbb{E}_{\mathbf{x} \sim p_{\text{data}}}[\log D(\mathbf{x})] + \mathbb{E}_{\mathbf{z} \sim p(\mathbf{z})}[\log(1 - D(G(\mathbf{z})))]ThegeneratorThe generatorGmapsnoisetosamples;thediscriminatormaps noise to samples; the discriminatorDclassifiesrealvsfake.Atequilibrium,classifies real vs fake. At equilibrium,D(\mathbf{x}) = 0.5forallfor all\mathbf{x}$.

Definition:

Spectral Normalisation

Constrains the Lipschitz constant of the discriminator by normalising each weight matrix by its spectral norm:

W^=W/σ(W)\hat{\mathbf{W}} = \mathbf{W} / \sigma(\mathbf{W})

from torch.nn.utils import spectral_norm
disc_conv = spectral_norm(nn.Conv2d(64, 128, 3, padding=1))

Example: DCGAN Generator

Implement a DCGAN generator using ConvTranspose2d.

GAN Training Dynamics

Watch generator and discriminator losses during training.

Parameters