Deep LearningGenerative Models

GAN vs VAE

Question 313 of 314 · Updated

On this page

Generative Adversarial Networks (GANs) and Variational Autoencoders (VAEs) both learn to generate new data, but they learn in fundamentally different ways. A GAN learns through competition between a generator and a discriminator. A VAE learns a probabilistic latent representation by optimizing a reconstruction objective and a regularized evidence lower bound (ELBO).

1. Core idea#

GAN: learn by adversarial competition#

A GAN contains two networks:

  • Generator : maps random noise to a synthetic sample .
  • Discriminator : predicts whether an input came from the real dataset or the generator.

The discriminator learns to distinguish real from generated samples, while the generator learns to fool the discriminator. Training is an adversarial game rather than direct per-example reconstruction.

LaTeX

In practice, many implementations use a non-saturating generator loss for stronger gradients.

VAE: learn a probabilistic latent space#

A VAE has an encoder and a decoder:

  • Encoder : maps an input to the parameters of a latent probability distribution, commonly a Gaussian with mean and variance .
  • Sampling: draws a latent vector from that distribution using the reparameterization trick.
  • Decoder : reconstructs the input or generates a new sample from .

The VAE maximizes the ELBO, commonly written as:

LaTeX

The first term rewards accurate reconstruction; the KL term regularizes the learned latent distribution toward a prior, often a standard normal distribution.

2. Side-by-side comparison#

DimensionGANVAE
Main componentsGenerator and discriminatorEncoder and decoder
Learning principleAdversarial gameVariational inference and reconstruction
Training objectiveAdversarial lossELBO: reconstruction plus KL regularization
Latent representationUsually samples a prior noise vector and maps it to dataLearns a distribution for each input
Training stabilityCan be difficult; networks must remain balancedOften more stable, though optimization and posterior collapse remain concerns
Typical visual outputCan produce sharp, realistic samplesOften smoother or blurrier under common likelihood choices
Mode coverageCan omit modes or collapse to limited outputsOften covers more of the distribution, sometimes at the cost of sample sharpness
LikelihoodStandard GANs do not provide an explicit tractable likelihoodProvides a variational lower bound on log likelihood
InferenceA standard GAN has no encoder; inversion requires an additional methodEncoder provides an approximate posterior for an input
ReconstructionNot inherent to an unconditional GANA central training objective
SamplingDraw noise from the prior and run the generatorDraw latent values from the prior and run the decoder
Common challengeMode collapse and unstable adversarial dynamicsBlurry reconstructions, posterior collapse, and a reconstruction–regularization trade-off

These are tendencies, not guarantees. Architecture, loss functions, dataset, and training procedure can substantially change the outcome.

3. A simple example#

Imagine training both models on a dataset of handwritten digits.

With a GAN:

  1. Sample a random noise vector, such as .
  2. The generator turns it into a synthetic digit image.
  3. The discriminator compares generated images with real training images.
  4. Update the discriminator to improve its real-versus-generated decisions.
  5. Update the generator so its outputs become harder to distinguish from real digits.
  6. Repeat the adversarial training process.

The generator is not normally asked to reconstruct a particular input digit. Its goal is to produce samples that resemble the dataset.

With a VAE:

  1. Give an image of digit 7 to the encoder.
  2. The encoder predicts a latent Gaussian, for example and .
  3. Sample a latent vector using , where .
  4. Pass through the decoder to reconstruct the digit.
  5. Optimize reconstruction quality while keeping the latent distribution close to the prior.
  6. To generate a new digit, sample directly from the prior and decode it.

The numerical values are illustrative, not measured model outputs.

4. Why can GAN samples look sharper?#

A common VAE uses a pixel-wise reconstruction likelihood, such as a Gaussian or Bernoulli distribution. When several outputs are plausible for the same input, minimizing expected reconstruction error can favor an averaged result. In image generation, that averaging can look smooth or blurry.

A GAN instead receives a learned signal from the discriminator about whether generated samples resemble real data. This can encourage sharper, more realistic-looking outputs.

However, sharpness is not the same as distribution coverage. A GAN may produce excellent-looking samples while missing important parts of the data distribution. A VAE may produce less sharp samples but offer a more structured latent representation and an explicit variational objective.

5. Training challenges#

GAN challenges#

  • Mode collapse: the generator produces a narrow range of samples instead of covering the diversity of the training data.
  • Training imbalance: a discriminator that becomes too strong or too weak can make generator learning difficult.
  • Sensitivity: results can depend on architecture, learning rates, normalization, and update schedules.
  • Evaluation: realistic-looking examples do not prove that the model covers the full data distribution.

Techniques such as Wasserstein GAN objectives, gradient penalty, and spectral normalization can improve aspects of GAN training, but they do not guarantee success.

VAE challenges#

  • Blurry outputs: common reconstruction likelihoods can favor averaged predictions.
  • Posterior collapse: the decoder may ignore the latent variable, causing the approximate posterior to approach the prior.
  • KL–reconstruction trade-off: excessive regularization can weaken useful information in the latent representation, while too little can produce poorly structured latent spaces.
  • Likelihood assumptions: the chosen decoder distribution may not capture the complexity of real data.

KL annealing, changes to decoder capacity, and alternative objectives can help with some VAE failure modes.

6. When should you use each?#

Consider a GAN when:

  • High visual fidelity or sharp synthetic samples are a major objective.
  • You can invest in careful adversarial training and evaluation.
  • The application benefits from a generator that maps noise directly to realistic samples.
  • You can monitor diversity and mode coverage, not only visual quality.

Consider a VAE when:

  • You need a useful, structured latent representation.
  • Reconstruction and interpolation are important.
  • You want an encoder that maps observed inputs to approximate latent distributions.
  • A probabilistic modeling objective and a variational likelihood bound are useful.

Neither is universally better. For some applications, hybrid approaches combine adversarial losses with VAE-style inference and reconstruction objectives.

7. How should you evaluate them fairly?#

Do not compare the models using only a handful of generated images.

  • Sample quality: use appropriate metrics such as FID or precision-oriented measures, alongside human inspection.
  • Distribution coverage: examine recall-oriented measures, class or cluster coverage, and diversity across repeated samples.
  • Reconstruction: evaluate reconstruction error for VAEs and for any GAN variant explicitly trained for reconstruction.
  • Likelihood: a VAE's ELBO is a variational lower bound, not the exact log likelihood. A standard GAN does not directly provide a tractable likelihood for the same comparison.
  • Downstream usefulness: test whether synthetic data improves the real task without introducing harmful artifacts or label errors.
  • Compute and stability: report training cost, failure rates, seeds, and tuning effort rather than only the best run.

Metrics have limitations and should be interpreted together with task-specific validation.

Key takeaway#

GANs learn to generate data by trying to fool a discriminator; VAEs learn to generate data through an encoder–decoder probabilistic model trained with reconstruction and latent regularization. GANs are often chosen for sharp sample quality, while VAEs are often chosen for structured latent representations, reconstruction, and probabilistic inference. The right choice depends on whether the task prioritizes realism, coverage, inference, reconstruction, or controllable representations.

Research references#

  1. Goodfellow et al., Generative Adversarial Nets (NeurIPS 2014).
  2. Kingma and Welling, Auto-Encoding Variational Bayes (ICLR 2014).
  3. B. D. et al., A high-bias, low-variance introduction to Machine Learning for physicists — section on VAEs and GANs.

Related questions

Explore other topics:Machine LearningLarge Language Models