Out-of-distribution Detection with Boundary Aware Learning

Sen Pei, Xin Zhang, Bin Fan, Gaofeng Meng

Abstract

There is an increasing need to determine whether inputs are out-of-distribution (OOD) for safely deploying machine learning models in the open world scenario. Typical neural classifiers are based on the closed world assumption, where the training data and the test data are drawn i.i.d. from the same distribution, and as a result, give over-confident predictions even faced with OOD inputs. For tackling this problem, previous studies either use real outliers for training or generate synthetic OOD data under strong assumptions, which are either costly or intractable to generalize. In this paper, we propose boundary aware learning (BAL), a novel framework that can learn the distribution of OOD features adaptively. The key idea of BAL is to generate OOD features from trivial to hard progressively with a generator, meanwhile, a discriminator is trained for distinguishing these synthetic OOD features and in-distribution (ID) features. Benefiting from the adversarial training scheme, the discriminator can well separate ID and OOD features, allowing more robust OOD detection. The proposed BAL achieves state-of-the-art performance on classification benchmarks, reducing up to 13.9% FPR95 compared with previous methods.

Introduction

Deep learning models typically operate under a "closed-world assumption," meaning they assume every input belongs to one of the classes they were trained on. When faced with out-of-distribution (OOD) data—images from a category the model has never seen—standard neural networks tend to be dangerously overconfident, assigning high-probability scores to completely irrelevant inputs.

Existing solutions often rely on using real outlier datasets during training (which is expensive and doesn't cover all possibilities) or generating synthetic data based on strong mathematical assumptions (like assuming features follow a Gaussian distribution). The authors argue that these assumptions often fail in high-dimensional feature spaces, leading to poor detection of "near-OOD" samples that sit right on the edge of the model's known world.

Methodology: Boundary Aware Learning (BAL)

The authors propose Boundary Aware Learning (BAL), which consists of three main modules designed to map the manifold of in-distribution (ID) data:

  1. Representation Extraction Module (REM): This module takes a pre-trained classifier and extracts features from its penultimate layer. It generates "trivial" OOD features by simply sampling uniformly across the entire feature space.
  2. Representation Sampling Module (RSM): To find the "hard" cases, BAL uses a Generator ($G$) to create synthetic ID features. It then applies the Fast Gradient Sign Method (FGSM) to intentionally push these synthetic features toward the boundary where the model starts to get confused. These become "hard" OOD features.
  3. Representation Discrimination Module (RDM): A discriminator ($D$) is trained to separate ID features from both trivial and hard OOD features. To make the boundary even sharper, the authors introduce Shuffle Loss (treating mislabeled ID features as OOD) and Uniform Loss (helping the model handle cases where a randomly sampled "trivial" feature lands too close to a real ID cluster).
The BAL framework architecture, showing the REM, RDM, and RSM modules working together to generate and discriminate OOD features.

Crucially, the pre-trained backbone remains frozen; BAL only trains the GAN components to learn the "uncertainty map" of the existing feature space.

Key Insights and Results

A core finding of this research is the "Gaussian Myth." The authors demonstrate that features in a neural network's final layers do not follow a simple Gaussian distribution. Methods that assume they do often miss the complex "narrow regions" where real data actually lives. By starting with easy (trivial) OOD samples and moving to difficult (hard) ones via adversarial pushing, the discriminator learns a much more robust boundary than it would with random noise alone.

Comparison of decision boundaries for ResNet18, MLP, and BAL. BAL (c) demonstrates a much tighter and more accurate boundary around the ID data clusters.

BAL achieved state-of-the-art (SOTA) performance across multiple benchmarks, specifically excelling in the FPR95 metric (the False Positive Rate at a 95% True Positive Rate). On the CIFAR-100 benchmark using a DenseNet backbone, BAL reduced the FPR95 to 11.3% when tested against LSUN, compared to 23.9% for the previous best method (Generalized ODIN). Overall, BAL reduced the FPR95 by up to 13.9% compared to previous SOTA methods.

Conclusion

Boundary Aware Learning provides a robust, GAN-based approach to OOD detection by focusing on the internal feature space rather than pixel-level generation. By adaptively learning the distribution of OOD features from trivial to hard, BAL enables a discriminator to precisely identify the limits of known data. While its performance is linked to the quality of the pre-trained backbone, its ability to learn tight decision boundaries significantly improves safety for open-world machine learning applications. Future work may extend this framework to more complex tasks like object detection.

Summary updated

Abstract

There is an increasing need to determine whether inputs are out-of-distribution (\emph{OOD}) for safely deploying machine learning models in the open world scenario. Typical neural classifiers are based on the closed world assumption, where the training data and the test data are drawn \emph{i.i.d.} from the same distribution, and as a result, give over-confident predictions even faced with \emph{OOD} inputs. For tackling this problem, previous studies either use real outliers for training or generate synthetic \emph{OOD} data under strong assumptions, which are either costly or intractable to generalize. In this paper, we propose boundary aware learning (\textbf{BAL}), a novel framework that can learn the distribution of \emph{OOD} features adaptively. The key idea of BAL is to generate \emph{OOD} features from trivial to hard progressively with a generator, meanwhile, a discriminator is trained for distinguishing these synthetic \emph{OOD} features and in-distribution (\emph{ID}) features. Benefiting from the adversarial training scheme, the discriminator can well separate \emph{ID} and \emph{OOD} features, allowing more robust \emph{OOD} detection. The proposed BAL achieves \emph{state-of-the-art} performance on classification benchmarks, reducing up to 13.9\% FPR95 compared with previous methods.
BibTeX
@inproceedings{pei2022out,
  author = {Sen Pei and Xin Zhang and Bin Fan and Gaofeng Meng},
  title = {{Out-of-distribution Detection with Boundary Aware Learning}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-20053-3\_14},
}
Figure