ElemedexA pocket encyclopedia of AI architectures
No. 021

GAN

Generative adversarial network

Counterfeiter

It always travels in pairs: one forges, the other inspects, and neither rests until the inspector is reduced to flipping a coin. The forger has never seen a real banknote; it learned everything from rejections. Its portraits of people who do not exist fool humans and machines alike.

Height
G: 3 · D: 3 (MLP, MNIST 2014)
Weight
≈ 15 MB (fp32, 2014)
Parameters
≈ 3.7 M (G 2.5 M + D 1.2 M; est.) · StyleGAN G: 26.2 M
Context
1 image (28 × 28 → 1024 × 1024)
Training data
MNIST · TFD · CIFAR-10 (2014) · FFHQ: 70,000 faces (StyleGAN)
Year
2014
Generation
3 · Deep learning
Creators
Goodfellow, Pouget-Abadie, Mirza, Xu, Warde-Farley, Ozair, Courville & Bengio (Université de Montréal)
Kind
Architecture

Base stats

Total
121

Approximate, ordinal scales meant for comparing species with each other; the hard numbers are in the data sheet.

Weaknesses

  • Mode collapse: many different seeds, the same image.
  • Unstable training: the balance between G and D is fragile.
  • No encoder and no explicit likelihood: hard to evaluate and hard to invert.
  • Raw material for deepfakes and disinformation.

Habitat

It was born among MNIST digits, faces from the Toronto Face Database and CIFAR-10 thumbnails, and grew up on portraits: celebrity faces and the 70,000 Flickr faces of FFHQ. Today it shows up on websites of people who do not exist, in the manufacture of synthetic data for training other models and, quietly, as an auxiliary loss inside the diffusion models that dethroned it.

Moves

Abilities

Minimax game
Two networks with opposite goals are trained together; the ideal equilibrium is a discriminator that answers ½ to everything.
Blind generator
G never sees a real data point: it learns only from the gradients D sends back.
Implicit density
It produces samples without ever writing down the probability distribution it imitates.

Anatomy

forgeriesgradient: fool DRandom noise zDense projectionTranspose convolutionsFake image G(z)Real imagesMixed: real or fake?Convolutional network DD(x) = P(real)min_G max_D V(D, G)Generator GDiscriminator D

Convolutional version, DCGAN-style: the generator lifts a noise vector up to an image; the discriminator receives real and fake images mixed together and estimates which are real. The gradient that flows through D is the only signal G receives. In the 2014 original, both networks were multilayer perceptrons.

Evolution chain

021 GAN

A generative adversarial network (GAN) is a pair of networks trained against each other: a generator that turns random noise into data (typically images) and a discriminator that tries to tell real data from forgeries. Goodfellow et al. (2014) introduced it with an analogy that became canonical: the generator is a team of counterfeiters trying to pass fake currency, the discriminator is the police trying to catch it, and the competition improves both until the copies are indistinguishable from the genuine article (2014, sec. 1).

How it works

The generator G takes a vector z drawn from a simple distribution (its latent space) and turns it into an image G(z). The discriminator D receives images and returns the probability that they are real. Both are trained by gradient descent on a single value, in a minimax game (Goodfellow et al., 2014, sec. 3):

V(D, G) = E[log D(x)] + E[log(1 − D(G(z)))]

D tries to maximize it (to be right); G tries to minimize it (to deceive). In practice, a few steps of D alternate with one step of G. Because early on D rejects the forgeries easily and G's gradient vanishes, the authors recommend that G maximize log D(G(z)) instead. At the theoretical optimum, the generator's distribution matches the data distribution and D answers ½ everywhere (2014, sec. 4).

A philosophically curious detail: the generator never sees a real image. It only receives the gradients that reach it through the discriminator, so no example is copied directly into its parameters (2014, sec. 6).

What changed

Compared with its ancestor, the multilayer perceptron, the novelty is not the architecture (in 2014, G and D were plain MLPs trained on MNIST, a Toronto face database and CIFAR-10 (2014, sec. 5)) but adversarial training: the generator's loss function is another network that is also learning. Earlier generative models stumbled on intractable probabilistic computations and Markov chains; a GAN needs only backpropagation. Unlike the VAE, it has no encoder and represents no explicit distribution (2014, sec. 6); in exchange, its samples tend to be sharper.

Evolution was fast. DCGAN (Radford et al., 2016) made the generator convolutional: according to Buckner (2024), its layers perform near-inverses of the operations in a network like AlexNet, with transpose convolutions that go from abstraction to detail (2024, pp. 58, 207–209). DCGAN brought latent arithmetic: the vector for "man with glasses," minus that for "man," plus that for "woman," yields women with glasses (2024, p. 213). StyleGAN (Karras et al., 2019) was trained on 70,000 Flickr faces at 1024 × 1024, and a descendant of it powers sites like This Person Does Not Exist (2024, p. 212). Chollet devotes a section to implementing a simple GAN on celebrity faces, with a "bag of tricks" to keep it stable (Chollet, 2021, sec. 12.5).

Limits

Since the early 2020s, diffusion models have displaced it in much of image generation. The idea survives as an auxiliary loss: the autoencoder of latent diffusion is trained with an adversarial objective to avoid blurriness (Rombach et al., 2022, sec. 3.1).

Sources