OOD Detection with Class Ratio Estimation

Mingtian Zhang, Andi Zhang, Tim Z. Xiao, Yitong Sun, Steven McDonaghMLSW @ NeurIPS 2022

TL;DR

This paper proposes a novel energy-based model framework to unify existing density-ratio based Out-of-Distribution (OOD) detection methods. Crucially, they introduce a class-ratio estimation technique to directly estimate density ratios, bypassing the need for computationally expensive deep generative models and achieving competitive OOD detection performance.

What Problem Does This Paper Address?

Machine learning models often assume that training and testing data come from the same distribution. However, in real-world applications, this assumption frequently breaks down, leading to model failures when encountering unexpected "out-of-distribution" (OOD) data. Detecting these OOD samples is critical for building reliable and safe AI systems. While density-based methods have shown promise for OOD detection, many lack a clear theoretical explanation. Existing density-ratio based methods, though empirically successful, often require training complex generative models, which can be computationally demanding and sometimes even assign higher densities to OOD data. This paper aims to provide a principled framework for density-ratio methods and propose a simpler, more efficient way to estimate these ratios for OOD detection.

Methods

The authors first propose an energy-based model framework to unify existing density-ratio methods. They model the in-distribution data ($p_{in}$) with an energy-based model $p_{in}(x) = p_{base}(x)s(x)/Z_{in}$, where $p_{base}$ is a base distribution and $s(x)$ is a "semantic score" function that assigns higher scores to in-distribution samples. This allows them to view the density ratio $p_{in}(x)/p_{base}(x)$ as proportional to the unnormalized density of an implicit semantic distribution.

The core novelty lies in their proposal to directly estimate this density ratio using class-ratio estimation. Instead of training generative models, they frame the problem as learning a binary classifier to distinguish between in-distribution ($y=1$) and base-distribution ($y=0$) samples. The density ratio $p_{in}(x)/p_{base}(x)$ is then directly estimated by the learned classifier's output ratio $p(y=1|x)/p(y=0|x)$. This approach avoids the need for complex generative models, significantly simplifying the OOD detection workflow.

To address potential issues with the support of $p_{base}$ not covering all possible OOD samples, they introduce a "spread density ratio" by adding Gaussian noise to both $p_{in}$ and $p_{base}$ before estimating the ratio. This helps stabilize training and improve distinguishability.

Datasets

The paper uses several standard datasets for training and evaluation:

  • In-distribution (ID) datasets: MNIST, FashionMNIST, CIFAR10, CIFAR100, KMNIST, Omniglot.
  • Out-of-distribution (OOD) datasets: notMNIST, SVHN, CelebA, LSUN.
  • Base distribution samples: They explore two strategies for constructing the base distribution ($p_{base}$):
  • Local Model: Samples are created by randomly cropping and resizing images from the in-distribution dataset.
  • Universal Model: Samples are drawn from a large, pre-existing dataset, specifically a 300K subset of the 80 Million Tiny Images dataset.

No new benchmarks are introduced, but the paper utilizes a comprehensive set of ID/OOD pairs to evaluate their method.

Key Insights and Ideas

  • Unifying Density Ratios: The energy-based model provides a principled way to understand various density-ratio based OOD detection methods, revealing their connection to semantic modeling.
  • Class Ratio Estimation for OOD: The most significant insight is that density ratios, crucial for OOD detection, can be effectively estimated using a simple binary classifier trained via class-ratio estimation. This bypasses the need for computationally intensive generative models.
  • "Density Chasm" Mitigation: The proposed "spread density ratio" (adding noise to both distributions) is a clever way to handle potential issues where the base distribution's support might not cover all OOD samples, improving robustness and training stability.
  • Computational Efficiency: By avoiding deep generative models, their method offers substantial computational savings during training, making OOD detection more accessible.

Key Results

  • The proposed class-ratio estimation method achieves competitive OOD detection performance, often comparable to or exceeding methods that require training generative models.
  • In Table 1, the "Universal Model" for $p_{base}$ construction consistently outperforms the "Local Model" across various ID-OOD pairs, suggesting that a broader base distribution is more effective.
  • Table 2 shows that their method (Ours-Universal) achieves competitive AUROC scores compared to methods like OE [11], Tiny-Glow [30], and Tiny-PCNN [30], while requiring zero generative model training. For example, on CIFAR10/SVHN, their AUROC is 98.2, compared to 94.4 for Tiny-PCNN.
  • Table 3 highlights that their approach uses 0 generative models, while other state-of-the-art methods require 1 to 5.
  • Figure 2 demonstrates that the "spread density ratio" (with noise) leads to significantly more stable AUROC curves during training compared to not using noise.

Limitations and Future Work

  • Base Distribution Construction: The paper acknowledges that the construction of the "local model" base distribution samples might not be optimal and suggests that further research into better local sample construction is a promising direction.
  • "Density Chasm" Sensitivity: While the spread density ratio helps, the paper notes that when $\sigma^2$ (the noise variance) is very small, there's still a danger of the classifier distinguishing based on noise level.
  • Future Work: The authors suggest further investigation into how to construct better base distributions ($p_{base}$) and explore more rigorous ways to apply their framework. They also hint at potential applications beyond image domain OOD detection.

Summary updated

BibTeX
@inproceedings{zhang2022ood,
  author = {Mingtian Zhang and Andi Zhang and Tim Z. Xiao and Yitong Sun and Steven McDonagh},
  title = {{OOD Detection with Class Ratio Estimation}},
  booktitle = {MLSW @ NeurIPS},
  year = {2022},
  url = {https://openreview.net/forum?id=Vu3TICIQHZP},
}
Figure