Generative adversarial networks: a generator and discriminator compete

Updated

A generative adversarial network uses two neural networks: a generator that produces fake data and a discriminator that tries to tell it from real data. They train together in a minimax game until the generator makes samples that the discriminator cannot reliably distinguish. This article explains the structure, training, and common variants.

The adversarial setup

Generative adversarial networks, or GANs, are generative models that create new data instances that resemble a training set. According to Google's GAN introduction, they can, for example, produce images that look like photographs of human faces even though the faces do not belong to any real person.

The original paper, described in the arXiv abstract, proposed that a generative model learns the distribution of training data while a discriminative model estimates whether a sample came from that data rather than from the generator.

How the generator and discriminator interact

In a GAN, the generator learns to produce plausible data, and the discriminator learns to distinguish real data from the generator's output. Google's GAN structure notes that the generated instances become negative training examples for the discriminator, and the discriminator penalizes the generator for implausible results.

IBM's GAN overview explains that the generator starts with random noise, also called a latent vector, and creates synthetic data. The discriminator evaluates both the generated samples and the training data, assigning a score between 0 and 1, where 1 indicates the data looks real. Backpropagation uses this feedback to adjust both networks. The competition continues until equilibrium is reached, where the discriminator can no longer distinguish fake from real.

Training and loss

The training process is often framed as a minimax game. PyTorch's DCGAN tutorial describes that the generator tries to minimize the probability that the discriminator predicts its outputs are fake, while the discriminator tries to maximize its probability of correctly classifying real and fake data.

Dive into Deep Learning's GAN chapter explains that the discriminator is a binary classifier trained with cross-entropy loss, and the generator is trained to maximize the discriminator's error. The chapter also notes that if the generator becomes perfect, the discriminator's loss approaches zero, which gives small gradients, so a different loss is often used for the generator.

Variants and applications

Several GAN variants exist. AWS's GAN explainer lists vanilla GANs, conditional GANs, and more advanced forms such as StyleGAN and CycleGAN. Each uses different mathematical formulations and interaction patterns between the generator and discriminator.

Common applications include generating images from text or by modifying existing images, augmenting training data with synthetic samples, completing missing information in datasets, and producing 3D models from 2D scans. These uses appear across industries such as entertainment, healthcare, and energy exploration.

GAN training flowStep 1: Generator produces fake sample from noise; Step 2: Discriminator compares fake and real samples; Step 3: Outputs probability that sample is real; Step 4: Update weights via backpropagation; Step 5: Repeat until generator fools discriminatorGAN training flowGenerator produces fake sample from noiseDiscriminator compares fake and real samplesOutputs probability that sample is realUpdate weights via backpropagationRepeat until generator fools discriminator
GAN training flow
Comparison of common GAN variants
VariantArchitectureKey characteristics
Vanilla GANMultilayer perceptrons for both networksBasic adversarial game, can be unstable during training
Conditional GAN (cGAN)Uses additional labels or conditions as inputEnables controlled generation, for example image-to-image translation
Deep Convolutional GAN (DCGAN)Convolutional layers in discriminator, transposed convolutional layers in generatorDesigned for high-quality image generation
StyleGANLayered generator architectureProduces high-resolution images with style control

Frequently asked questions

What is a GAN?

A GAN is a machine learning model with two neural networks, a generator and a discriminator, that compete to create realistic data.

How do the generator and discriminator train together?

The generator tries to produce data that the discriminator cannot distinguish from real data, while the discriminator tries to correctly classify real and fake samples. This adversarial process improves both networks.

What is the minimax game in GAN training?

The training is framed as a minimax game where the generator minimizes the probability that the discriminator detects fakes, and the discriminator maximizes its classification accuracy.

What are common GAN variants?

Common variants include vanilla GAN, conditional GAN, deep convolutional GAN (DCGAN), and StyleGAN, each with different architectures and use cases.

What are typical applications of GANs?

GANs are used for image generation, data augmentation, filling missing data, and creating 3D models from 2D inputs.