Improving Out-of-Distribution Detection with Disentangled Foreground and Background Features

Choubo Ding, Guansong Pang

TL;DR

Deep neural networks often fail when they encounter out-of-distribution (OOD) data because they conflate foreground objects with background noise. This paper introduces DFB (Disentangled Foreground and Background), a framework that explicitly separates these features to improve OOD detection, achieving new state-of-the-art results by simply plugging into existing detection methods.

What Problem Does This Paper Address?

In the real world, AI models frequently encounter inputs they weren't trained on—known as out-of-distribution (OOD) data. A self-driving car trained on city streets might struggle when it sees a snowy mountain pass. Ideally, the model should flag these as "unknown" rather than making a confident, incorrect guess.

Current OOD detection methods primarily focus on foreground features (the actual objects, like a "horse"). However, the authors point out two major flaws in this approach:

  1. Spurious Correlations: Models might learn that a "horse" always comes with a "rider," leading them to misclassify OOD images containing people as horses.
  2. Foreground-Background Confusion: Models often mistake the background of an OOD image for a foreground object they recognize. As shown in saliency maps, vanilla classifiers often struggle to localize objects in OOD data, treating background textures as meaningful foreground features.

Methods

The authors propose a novel framework called DFB that disentangles these features using a multi-step process:

  1. Segment and Learn: Starting with a standard $K$-class classifier, they use Class Activation Mapping (CAM) to generate "pseudo-segmentation masks." These masks identify which parts of an image are foreground (the object) and which are background.
  2. Dense Prediction Training: They train a new network to perform a dense prediction task (pixel-wise classification). This network has $K+1$ classes: the original $K$ object classes plus one additional class specifically for the in-distribution background.
  3. Lossless Conversion: A key technical contribution is the "lossless conversion" shown in Figure 3. The dense prediction network (which uses upsampling) is converted back into a standard classification network (using Global Average Pooling) without needing any retraining. This allows the model to benefit from spatial disentanglement while functioning as a fast classifier.
  4. Joint OOD Scoring: During testing, the model produces both foreground scores (using existing methods like Energy or ViM) and a background score from the new $(K+1)$-th class. These are combined to form a final, more robust OOD score.
Figure 3: Lossless conversion of a dense prediction network to a classification network.
Figure 2: Overview of our proposed framework. It first uses a trained 𝐾-class classification network to obtain pseudo semantic segmentation masks and then learns the in-distribution features by training a (𝐾+ 1)-class classification network with the pseudo labels (Left). It lastly converts the dense prediction network to a (𝐾+1)-class classifier in a lossless fashion, and leverages these (𝐾+ 1) prediction outputs for joint foreground and background OOD detection (Bottom Right).

Datasets

The researchers evaluated DFB using several standard benchmarks:

  • In-Distribution (ID): CIFAR10, CIFAR100, and large-scale ImageNet-1k.
  • Out-of-Distribution (OOD): SVHN (house numbers), Places365 (scenes), Textures, and cross-testing between CIFAR10/100. For ImageNet experiments, they used ImageNet-O and SUN.

Key Insights and Ideas

  • Background is a Signal, Not Just Noise: Most researchers treat background as something to ignore. This paper argues that knowing what a "normal" background looks like for your training data is a powerful tool for spotting OOD samples that have "weird" backgrounds.
  • Disentanglement Reduces "Hallucinations": By explicitly training a background class, the model is less likely to "see" a foreground object where none exists in OOD data.
  • Plug-and-Play Compatibility: DFB isn't a standalone detector; it's a framework that enhances existing state-of-the-art (SotA) methods like MSP, ODIN, Energy, and ViM.
  • Spatial Awareness Matters: Even for simple classification, forcing the model to learn where the object is (via the dense prediction task) makes the resulting features much more discriminative for OOD detection.

Key Results

DFB consistently and substantially improved the performance of all four base OOD detection methods it was tested with.

  • Significant Error Reduction: On the CIFAR100 benchmark, DFB improved the average FPR95 (False Positive Rate at 95% True Positive Rate) by 11.78%.
  • New State-of-the-Art: The combination of ViM-DFB achieved the best overall performance, reaching an average FPR95 of just 3.65% when CIFAR10 was the in-distribution dataset.
  • Better Feature Separation: t-SNE visualizations in the paper demonstrate that DFB creates much cleaner clusters for ID data and pushes OOD samples further away in the feature space compared to vanilla classifiers.
  • Maintains Accuracy: Importantly, this focus on OOD detection does not hurt standard classification performance. In fact, on CIFAR100, DFB slightly improved Top-1 accuracy (from 85.94% to 86.17%).
Figure 5: t-SNE visualization of the features learned by the vanilla classification network and DFB, where the colored dots are ID samples of different classes, and the black × are OOD samples.

Limitations and Future Work

  • The "Large-Scale" Challenge: While DFB outperforms baselines on ImageNet, OOD detection remains difficult as the number of classes grows. The authors noted that performance for all methods degrades as the semantic space expands.
  • Hyperparameter Tuning: The method introduces a temperature parameter ($T$) to balance foreground and background scores. While a default value of 2.5 worked well across most tests, optimal performance might require some tuning for specific, unusual datasets.
  • Future Directions: The authors plan to apply these disentanglement principles to zero-shot and few-shot OOD detection, potentially using large pre-trained vision-language models (like CLIP) and prompt engineering.

Summary updated

Abstract

Detecting out-of-distribution (OOD) inputs is a principal task for ensuring the safety of deploying deep-neural-network classifiers in open-set scenarios. OOD samples can be drawn from arbitrary distributions and exhibit deviations from in-distribution (ID) data in various dimensions, such as foreground features (e.g., objects in CIFAR100 images vs. those in CIFAR10 images) and background features (e.g., textural images vs. objects in CIFAR10). Existing methods can confound foreground and background features in training, failing to utilize the background features for OOD detection. This paper considers the importance of feature disentanglement in out-of-distribution detection and proposes the simultaneous exploitation of both foreground and background features to support the detection of OOD inputs in in out-of-distribution detection. To this end, we propose a novel framework that first disentangles foreground and background features from ID training samples via a dense prediction approach, and then learns a new classifier that can evaluate the OOD scores of test images from both foreground and background features. It is a generic framework that allows for a seamless combination with various existing OOD detection methods. Extensive experiments show that our approach 1) can substantially enhance the performance of four different state-of-the-art (SotA) OOD detection methods on multiple widely-used OOD datasets with diverse background features, and 2) achieves new SotA performance on these benchmarks.
BibTeX
@inproceedings{ding2024improving,
  author = {Choubo Ding and Guansong Pang},
  title = {{Improving Out-of-Distribution Detection with Disentangled Foreground and Background Features}},
  booktitle = {ACM Multimedia},
  year = {2024},
  doi = {10.1145/3664647.3681614},
}
Figure