Learning to Shape In-distribution Feature Space for Out-of-distribution Detection

Yonggang Zhang, Jie Lu, Bo Peng, Zhen Fang, Yiu-ming CheungNeurIPS 2024

In the "open-world" of real-world deployment, machine learning models frequently encounter inputs they’ve never seen before—known as Out-of-Distribution (OOD) data. Whether it is a self-driving car encountering a tumbleweed for the first time or a medical AI analyzing a rare, unmodeled pathology, the system needs to reliably say "I don't know" rather than making a confident, incorrect guess.

Traditionally, researchers have treated OOD detection as a "post-hoc" problem: models are trained normally, and researchers subsequently attempt to find clever ways to measure "uncertainty" from the outputs. However, a new paper titled "Learning to Shape In-distribution Feature Space for Out-of-distribution Detection" argues for a more proactive approach. Instead of trying to fix the feature distribution after the fact, the authors propose shaping it deterministically while the model is learning.

The Distributional Mismatch Problem

Most OOD detection methods rely on a fundamental assumption: that "In-Distribution" (ID) data—the data the model was trained on—clusters into neat, predictable shapes (like Gaussians) in the model's feature space. Unfortunately, standard training using Cross-Entropy loss does not guarantee this structure. It only optimizes for pushing classes far enough apart to classify them accurately.

This creates a "distributional mismatch." The scoring functions used to detect OOD data assume a mathematical structure that isn't actually present in the learned features. To resolve this, the authors introduce Distributional Representation Learning (DRL), a framework that explicitly forces a model’s internal features to follow a pre-defined mixture distribution during training.

The DRL Framework

The core of the paper moves OOD detection from a reactive post-hoc analysis to a proactive training constraint through several key mechanisms:

  1. Distributional Modeling: Instead of letting features land arbitrarily, DRL enforces the feature space to conform to a von Mises-Fisher (vMF) mixture distribution. This is particularly effective because modern deep learning often utilizes $\ell_2$-normalized features, effectively projecting them onto a hypersphere.
  2. Online Approximation: A major hurdle in using vMF distributions is calculating the "normalization constant," which involves complex Bessel functions that are traditionally too slow to compute during every training step. The authors solve this using a uniform expansion technique, allowing for fast, online approximation that enables end-to-end training.
  3. Expectation-Maximization (EM) Optimization: To prevent the model from finding "trivial solutions" (such as collapsing all features into a single point), training is formulated as an EM algorithm.
  4. E-step: Estimates "soft labels" based on the current model.
  5. M-step: Maximizes the Evidence Lower Bound (ELBO) to align features with the target distribution.
  6. Sequential Sampling: To keep the EM process stable during batch-based training, the authors rearrange how data is sampled so that half of each mini-batch overlaps with the previous one, ensuring consistency in the "soft labels."

Key Insights

  • Proactive vs. Reactive: The primary breakthrough is recognizing that we shouldn't just hope features resemble a Gaussian or vMF distribution; we should force them to by baking that requirement directly into the loss function.
  • Class-Specific Tightness: Unlike previous works that assumed every class has the same "concentration" (tightness) in feature space, DRL allows the model to learn the concentration parameter for each class independently. This flexibility leads to significantly better generalization.
  • The ELBO as a Metric: By maximizing the ELBO during training, the model naturally learns a scoring function that is theoretically grounded in the true density of the ID data.

Key Results

The authors evaluated DRL across a rigorous gauntlet of benchmarks, including standard OOD detection, Hard OOD (where OOD classes are semantically similar to ID classes), and Unsupervised OOD scenarios. DRL consistently outperformed or matched state-of-the-art methods.

Standard OOD Detection

On CIFAR-10, DRL achieved an average FPR95 of 11.58% (False Positive Rate at 95% True Positive Rate), significantly beating the previous leading method, PALM (14.96%).

OOD Detection Performance on CIFAR-10

Hard OOD Detection

On the much more challenging task of distinguishing CIFAR-100 from semantically similar OOD data, DRL maintained its superiority. It achieved a 60.88% FPR95, outperforming PALM's 64.40%.

Hard OOD Detection Performance

Furthermore, even without ground-truth labels (using pseudo-labels from a DINO-style teacher in an unsupervised setting), DRL maintained strong performance, demonstrating that it does not strictly rely on perfect human labeling to effectively shape the feature space.

Limitations and Future Work

While DRL represents a powerful step forward, the authors note a few areas for future exploration:

  • Density Function Variety: This research focused on one specific realization of the density function (vMF). Exploring other non-negative density functions could yield even better results for different data modalities.
  • Pipeline Complexity: The requirement for sequential sampling and the EM framework adds complexity to the standard training pipeline, which may require additional tuning when adapting to novel architectures.

Ultimately, DRL demonstrates that if we want a model to know what it doesn't know, we must be intentional about how it learns what it does know. By proactively shaping the feature space from day one, we can build safer, more reliable AI systems ready for the open world.

Summary updated

BibTeX
@inproceedings{zhang2024learning,
  author = {Yonggang Zhang and Jie Lu and Bo Peng and Zhen Fang and Yiu-ming Cheung},
  title = {{Learning to Shape In-distribution Feature Space for Out-of-distribution Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=1Du3mMP5YN},
}
Figure