ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Advanced GAN techniques
Chapter 1: GAN Foundations Revisited
The Generator-Discriminator Architecture
The Minimax Objective Function
Common Training Instabilities
Limitations of Vanilla GANs
Deep Convolutional GANs (DCGANs) Refresher
Chapter 2: Advanced GAN Architectures
Progressive Growing of GANs (ProGAN)
Style-Based Generator Architecture (StyleGAN)
StyleGAN2 Enhancements
Large Scale GAN Training (BigGAN)
Self-Attention Mechanisms in GANs
Unpaired Image-to-Image Translation (CycleGAN)
Implementing StyleGAN Components: Hands-on Practical
Chapter 3: GAN Training Dynamics and Stabilization
The Challenge of Non-Convergence
Mode Collapse: Causes and Consequences
Alternative Divergences: Wasserstein Distance
Weight Clipping in WGAN
Gradient Penalty (WGAN-GP)
Spectral Normalization
Two Time-Scale Update Rule (TTUR)
Relativistic GANs
Implementing WGAN-GP: Practice
Chapter 4: Conditional and Controllable Generation
Introduction to Conditional GANs (cGANs)
Architectures for cGANs
Information Maximizing GANs (InfoGAN)
StackGAN: Text-to-Image Synthesis
Controlling Attributes via Latent Space Manipulation
Disentanglement Metrics and Challenges
Building a Conditional GAN: Hands-on Practical
Chapter 5: Quantitative and Qualitative Evaluation of GANs
Challenges in Evaluating Generative Models
Qualitative Assessment: Visual Turing Tests
Inception Score (IS): Formulation and Limitations
Fréchet Inception Distance (FID): Formulation
Interpreting FID Scores
Precision and Recall for Distributions
Perceptual Path Length (PPL)
Calculating FID Score: Practice
Chapter 6: GANs Beyond Standard Image Generation
Challenges with Discrete Data: Text Generation
Reinforcement Learning Approaches (SeqGAN, RankGAN)
Continuous Approximations (Gumbel-Softmax)
Audio Synthesis with GANs (WaveGAN, SpecGAN)
Video Generation and Prediction
3D Data Generation (Point Clouds, Meshes)
Graph Generation with GANs
Chapter 7: Implementation, Optimization, and Tooling
Choosing Deep Learning Frameworks
Advanced Optimizers (AdamW, Lookahead)
Hyperparameter Tuning Strategies
Weight Initialization Techniques
Debugging Unstable GAN Training
Mixed Precision Training
Distributed Training Strategies for Large GANs
Profiling and Performance Optimization
Optimizing a GAN Implementation: Practice

Precision and Recall for Distributions

While metrics like Fréchet Inception Distance (FID) provide a single score summarizing GAN performance, they conflate two distinct aspects: the fidelity (quality or realism) of generated samples and the diversity (variety or coverage) of those samples relative to the real data distribution. A low FID score is desirable, but it doesn't tell us why a model might be performing poorly. Is it generating unrealistic images (low fidelity), or is it failing to capture the full variety of the data (low diversity, possibly mode collapse)?

To gain more specific insights, we can adapt the concepts of precision and recall, traditionally used in information retrieval and classification, to the evaluation of generative models. In the context of GANs, these metrics help disentangle the assessment of sample quality from the assessment of distributional coverage.

Understanding Precision and Recall for GANs

Imagine comparing the distribution of generated samples, PgP_gPg​, with the distribution of real samples, PrP_rPr​.

  • Precision measures the fidelity of the generated samples. It answers the question: "Of the samples the generator produced, what fraction are realistic or plausible samples from the target distribution?" High precision indicates that the GAN generates few "fake-looking" or artifact-ridden samples. It relates to the quality aspect.
  • Recall measures the diversity or coverage of the generated samples relative to the real data. It answers: "Of all the types of samples present in the real dataset, what fraction can the generator actually produce?" High recall indicates that the generator captures most of the variations and modes present in the real data distribution. It relates to the diversity aspect.

Here are some scenarios:

  1. High Precision, Low Recall: The GAN generates very realistic samples (high quality), but only covers a small subset of the true data variety (e.g., mode collapse).
  2. Low Precision, High Recall: The GAN generates a wide variety of samples covering most of the real data modes, but many of these samples are unrealistic or contain artifacts.
  3. Low Precision, Low Recall: The worst case. The GAN produces poor-quality samples and fails to capture the diversity of the real data.
  4. High Precision, High Recall: The ideal scenario. The GAN produces high-quality, realistic samples that cover the full diversity of the real data distribution.

A Practical Approach to Calculation

Calculating precision and recall for continuous, high-dimensional distributions requires a practical methodology. One common approach, proposed by Kynkäänniemi et al. (2019), involves analyzing the proximity of samples in a suitable feature space:

  1. Embedding: Embed a large number of real samples (NrN_rNr​) and generated samples (NgN_gNg​) into a feature space. This is often done using the activations from an intermediate layer of a pre-trained network, like Inception V3, similar to how FID is calculated. Let these feature vectors be xr∈Rdx_r \in \mathbb{R}^dxr​∈Rd for real samples and xg∈Rdx_g \in \mathbb{R}^dxg​∈Rd for generated samples.
  2. Nearest Neighbors: For each real sample xrx_rxr​, find its kkk-th nearest neighbor among all other real samples in the feature space based on Euclidean distance. Let the distance to this neighbor be d(xr,NNk(xr))d(x_r, \text{NN}_k(x_r))d(xr​,NNk​(xr​)). Similarly, for each generated sample xgx_gxg​, find the distance to its kkk-th nearest neighbor among all other generated samples, d(xg,NNk(xg))d(x_g, \text{NN}_k(x_g))d(xg​,NNk​(xg​)). The value of kkk (e.g., k=3k=3k=3 or k=5k=5k=5) is a hyperparameter. These distances define approximate local density estimates around each point.
  3. Precision Calculation: For each generated sample xgx_gxg​, determine if it falls within the "manifold" of the real data. This is done by checking if there is at least one real sample xrx_rxr​ such that the distance ∥xg−xr∥2≤d(xr,NNk(xr))\|x_g - x_r\|_2 \leq d(x_r, \text{NN}_k(x_r))∥xg​−xr​∥2​≤d(xr​,NNk​(xr​)). In simpler terms, we check if the generated sample xgx_gxg​ is closer to a real sample xrx_rxr​ than xrx_rxr​ is to its kkk-th nearest real neighbor. Precision is the fraction of generated samples xgx_gxg​ for which this condition holds. Precision=1Ng∑i=1NgI(∃j:∥xg,i−xr,j∥2≤d(xr,j,NNk(xr,j)))\text{Precision} = \frac{1}{N_g} \sum_{i=1}^{N_g} \mathbb{I} \left( \exists j : \|x_{g,i} - x_{r,j}\|_2 \leq d(x_{r,j}, \text{NN}_k(x_{r,j})) \right)Precision=Ng​1​i=1∑Ng​​I(∃j:∥xg,i​−xr,j​∥2​≤d(xr,j​,NNk​(xr,j​))) where I(⋅)\mathbb{I}(\cdot)I(⋅) is the indicator function.
  4. Recall Calculation: For each real sample xrx_rxr​, determine if it is well-represented by the generated distribution. This is done by checking if there is at least one generated sample xgx_gxg​ such that the distance ∥xr−xg∥2≤d(xg,NNk(xg))\|x_r - x_g\|_2 \leq d(x_g, \text{NN}_k(x_g))∥xr​−xg​∥2​≤d(xg​,NNk​(xg​)). Recall is the fraction of real samples xrx_rxr​ for which this condition holds. Recall=1Nr∑j=1NrI(∃i:∥xr,j−xg,i∥2≤d(xg,i,NNk(xg,i)))\text{Recall} = \frac{1}{N_r} \sum_{j=1}^{N_r} \mathbb{I} \left( \exists i : \|x_{r,j} - x_{g,i}\|_2 \leq d(x_{g,i}, \text{NN}_k(x_{g,i})) \right)Recall=Nr​1​j=1∑Nr​​I(∃i:∥xr,j​−xg,i​∥2​≤d(xg,i​,NNk​(xg,i​)))

Interpreting Precision and Recall Scores

These metrics are typically reported together, often visualized on a Precision-Recall plot. This allows for a more detailed comparison between different models or training checkpoints.

Comparing GAN models on a Precision-Recall plot. The ideal model resides in the top-right corner (High Precision, High Recall). Different locations indicate different trade-offs or failure modes. Model B shows high precision but low recall, suggesting mode collapse. Model C shows high recall but low precision, suggesting poor sample quality despite diversity. Model D performs poorly on both axes. Model A represents a better balance.

A model improving primarily along the precision axis is getting better at generating realistic samples, even if it doesn't cover all modes. Improvement along the recall axis means it's capturing more of the data's diversity, possibly at the expense of some realism initially. The goal is to push towards the top-right corner.

Advantages

Advantages:

  • Disentangled Evaluation: Provides separate scores for fidelity (precision) and diversity (recall), offering clearer diagnostics than single-score metrics like FID.
  • Mode Collapse Detection: Low recall combined with high precision is a strong indicator of mode collapse.
  • Quality Assessment: Low precision suggests problems with sample realism or artifacts, regardless of diversity.

Key Points:

  • Feature Space: The choice of embedding network significantly impacts the results. Using standard pre-trained models like Inception V3 is common for comparability, but may not be optimal for all datasets or tasks.
  • Hyperparameter kkk: The number of nearest neighbors kkk influences the locality of the comparison. The original paper suggests k=3k=3k=3 or k=5k=5k=5, but sensitivity analysis might be needed.
  • Computational Cost: Calculating k-NN distances for large datasets in high-dimensional feature spaces can be computationally expensive compared to FID. Efficient k-NN algorithms (e.g., using libraries like Faiss) are often necessary.
  • Bias: Like FID and IS, these metrics inherit any biases present in the pre-trained feature extractor.

By using precision and recall alongside other metrics like FID, you can develop a more comprehensive understanding of your GAN's performance, pinpointing specific areas for improvement in terms of both the quality and the diversity of the generated samples.

  • Improved Precision and Recall Metric for Assessing Generative Models, Tuomas Kynkäänniemi, Tero Karras, Samuli Laine, Jaakko Lehtinen, and Timo Aila, 2019 Advances in Neural Information Processing Systems (NeurIPS), Vol. 32 (Advances in Neural Information Processing Systems) DOI: 10.48550/arXiv.1904.06991 - Introduces the precision and recall metrics for generative models, providing a detailed methodology for their calculation in a feature space.
  • GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium, Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler, Sepp Hochreiter, 2017 Advances in Neural Information Processing Systems, Vol. 30 (Curran Associates, Inc.) DOI: 10.55985/9142f36f6d289299 - Introduces the Fréchet Inception Distance (FID) as a widely used metric for assessing the quality of generated images, establishing a context for the need for more nuanced evaluation.
  • A Survey on Generative Adversarial Networks: Recent Advances, Challenges, and Future Directions, Yu-An Liu, Kai-Xuan Chen, Zhi-Bo Wang, Qi-Ming Huang, and Jun-Liang Ma, 2021 IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 44 (IEEE) DOI: 10.1109/TPAMI.2021.3121516 - Provides a broad review of GANs, including a section on evaluation metrics that contextualizes precision and recall among other methods for assessing generative models.

© 2026 ApX Machine Learning