ai papers
An Introduction to Generative Adversarial Networks (GANs)
Junyoung Park · 2022-12-09 · 9 min
This article introduces generative adversarial networks (GANs). I had already written about VAEs and diffusion models, so leaving out the most famous and extensively studied family of generative models felt incomplete. GAN research remains active: beyond style-controlled image generation with models such as StyleGAN, it covers 3D scene-aware generation, depth-map generation, and many other fields. One of the greatest practical advantages of GANs is their fast sampling speed.
Background
A generative model attempts to reproduce a desired data distribution. Although a GAN is not an explicit likelihood-based model, its objective likewise constructs a similar distribution. It defines a mapping from a latent space to a data space . Let us first review the probability concepts needed to understand that mapping.
Probability
In the figure, suppose the red random variable is and the blue one is . Both are Gaussian for simplicity.
We can define a distribution over the variables together, their joint probability . The two variables may or may not be related. The joint of and appears as a three-dimensional Gaussian over the plane between their axes. Because these Gaussian marginals are symmetric around their means, the illustrated joint is isotropic.
Projecting the joint distribution onto either axis recovers the corresponding marginal or :
For discrete probability mass functions, integration becomes summation:
Integrating along an axis in multiple dimensions adds all of its values and therefore acts as a projection.
As noted above, the variables may be related. If they are independent—say, the chance that a passerby is my ideal type and the chance of rain tomorrow—the relationship is irrelevant. When they are dependent, conditional probability contains information distinct from the marginal and joint. The distribution of given a particular is
Modeling and Sampling a Probability Density
A traditional density-modeling process can be summarized as follows:
- Collect sample data whose distribution we want to estimate.
- Estimate an empirical probability density function from the samples.
- Fit a standard parametric density to that empirical density.
- Estimate its parameters with maximum-likelihood estimation, Bayesian estimation, or another method.
Sampling reverses the fitted mapping: . This brief description assumes familiarity with MLE and Bayesian methods, so we will move on rather than derive them here.
Generative and Discriminative Models
In one sentence, a GAN improves performance by making a generator and discriminator compete. Modern life is competitive enough already, with everyone worrying about résumés and self-improvement. I am not sure that analogy helps.
The generator and discriminator correspond to two broad classes of statistical model. A generative model represents a joint density or a marginal density . Neural networks learn functions implicitly; here we can think of the generator as learning parameters that define a distribution. A discriminative model instead learns a conditional density and distinguishes plausible data produced by the generator.
Although both were written with , the two networks actually optimize separate parameter sets, such as and . Examples of generative models include Gaussian mixture models, hidden Markov models, Bayesian networks, deep belief networks, and deep Boltzmann machines. Discriminative models include familiar encoders for low-level tasks: MLPs, CNNs, logistic regression, SVMs, and many others.
General Data Generation
The broad aim of a generative model is to use a decoder-like generator to create plausible data by learning . Because the real data density is difficult to obtain directly, we often introduce a joint distribution and optimize quantities we can access without needing every term in Bayes' rule:
Here we focus not on explicit optimization of likelihood , but on the marginal . Integrating the joint over every averages the likelihood over a prior distribution that we can choose:
A common choice is . A sampled is called a latent vector or latent variable. Passing it through the generator produces a sample under the model induced by and , which we try to fit to the empirical data distribution.
Characteristics of GANs
The original GAN paper contains the full core idea. A GAN learns an implicit density. Because it receives no direct supervision for a joint probability from which to create , it can be viewed as an unsupervised approach.
The model has two networks: a generative network and a discriminative network , trained in competition.
The usual analogy is a counterfeiter and the police. The generator, or counterfeiter, tries to create convincing fake data; the discriminator, or police, learns to distinguish fake examples from genuine ones. The minimax objective is
The logarithms are log-likelihood terms applied to probabilities between zero and one.
The Discriminator's Perspective
A real example should be classified as true, so an ideal discriminator makes and . A fake example produced from should be classified as false, giving and .
The discriminator therefore maximizes . If it seems strange that the maximum is zero, remember that the log of a probability in lies in .
The Generator's Perspective
The generator affects only the second term. It wants fake data to fool the discriminator—that is, it wants the discriminator to call the fake genuine. Under the original minimax form, the generator therefore minimizes , whose ideal limit is .
Together, these perspectives explain the minimax game: the two networks optimize in opposite directions, and their competition shapes both parameter sets.
Along one axis the objective is convex and along the other it is concave, so the desired global equilibrium is a saddle point. A figure in the original paper makes this process more intuitive.
Blue shows the discriminator's decision function, black the real data distribution, and green the generator distribution. In (a), neither network is well optimized: the generator's mapping does not follow the real data, and the discriminator separates examples only roughly. After discriminator training in (b), it distinguishes real from fake more confidently. Training the generator from this state produces (c), where the green generated distribution moves toward the black data distribution. At convergence in (d), the generator matches the real distribution and the discriminator can no longer tell real and fake apart. This is the saddle-point equilibrium described above.
The training algorithm performs discriminator updates for each generator update. In terms of the figure,
The Objective as Jensen–Shannon Divergence
The minimax expression can be rewritten in terms of Jensen–Shannon divergence:
Here the distribution induced by the generator is denoted directly by , absorbing the explicit mapping. At the optimum, and . Substitution gives
The figure shows generated results on MNIST, TFD, and CIFAR-10.
Metrics for GANs
A GAN is a generative model, so ordinary supervised metrics for discriminative models do not directly evaluate it. A good generator must produce not only attractive images, but diverse and plausible ones. Three metrics are commonly discussed.
IS: Inception Score
Inception Score measures both quality and diversity:
If generated images are diverse, the marginal should spread across classes and have high entropy. This term reflects diversity. At the same time, each generated image should look unambiguously like its predicted label . Confidence in the individual sample reflects quality, so should have low entropy.
The conditional map is the softmax output of an Inception network, and the marginal over all samples is
Low diversity makes sparse, resembling a one-hot vector; high diversity makes it dense and closer to a high-entropy uniform distribution. Across generated samples,
FID: Fréchet Inception Distance
Inception Score has a serious weakness: a generator can produce only one image per class—a form of mode collapse—and still appear diverse. If it overfits to a single easy sample for every class, IS can remain high.
Fréchet Inception Distance instead extracts intermediate Inception features and models their multivariate Gaussian distributions using means and covariances :
The metric compares the distributions of real and generated data and is generally more robust to noise than IS. A generator that emits only one image per class differs strongly from the covariance structure of the real data, producing a worse—larger—FID. FID therefore captures within-class diversity more effectively.
LPIPS: Learned Perceptual Image Patch Similarity
LPIPS is comparatively simple:
Feature extractors such as AlexNet, VGG, or SqueezeNet produce activation maps for reference image and measured image . LPIPS calculates the Euclidean distance between activations and , scales channels by layer weights , averages over spatial positions, and sums across layers. Because it compares learned feature maps rather than raw pixels, it serves as a perceptual patch-similarity metric. The layer weights are learned parameters, which explains the “Learned” in the paper's title.