On the Impact of Spurious Correlation for Out-of-Distribution Detection

Yifei Ming, Hang Yin, Yixuan Li

Abstract

Modern neural networks can assign high confidence to inputs drawn from outside the training distribution, posing threats to models in real-world deployments. While much research attention has been placed on designing new out-of-distribution (OOD) detection methods, the precise definition of OOD is often left in vagueness and falls short of the desired notion of OOD in reality. In this paper, we present a new formalization and model the data shifts by taking into account both the invariant and environmental (spurious) features. Under such formalization, we systematically investigate how spurious correlation in the training set impacts OOD detection. Our results suggest that the detection performance is severely worsened when the correlation between spurious features and labels is increased in the training set. We further show insights on detection methods that are more effective in reducing the impact of spurious correlation, and provide theoretical analysis on why reliance on environmental features leads to high OOD detection error. Our work aims to facilitate better understanding of OOD samples and their formalization, as well as the exploration of methods that enhance OOD detection.

Introduction

Deep learning models are notorious for "not knowing what they don't know." Out-of-distribution (OOD) detection aims to identify test inputs that are semantically different from the training data so the system can take safety precautions. However, the current definition of OOD is often too simplistic. Most benchmarks focus on "non-spurious" OOD (e.g., showing a picture of a cat to a model trained only on birds).

In reality, models often rely on spurious correlations—statistically informative but non-essential features like backgrounds or textures. If a model learns that "water" equals "waterbird," it may fail when encountering a "boat" on water. This paper investigates how these training-set biases impact OOD detection performance, a nuance largely ignored in prior literature.

Methodology and Formalization

The authors introduce a new formalization of the data model, decomposing an input $x$ into two types of latent features:

  1. Invariant Features ($z_{inv}$): Essential semantic cues (e.g., the shape of a beak for a bird).
  2. Environmental Features ($z_e$): Non-invariant cues that are spuriously correlated with the label (e.g., a water background).

Based on this, they define two categories of OOD data:

  • Spurious OOD: Samples that contain the environmental feature ($z_e$) but lack the invariant semantic feature ($z_{inv}$). Example: A boat on water for a waterbird classifier.
  • Non-spurious OOD: Conventional OOD samples that contain neither feature. Example: An indoor cat for a waterbird classifier.
Illustration of training examples with spurious correlations and the distinction between spurious and conventional OOD testing examples.

The researchers systematically vary the correlation ($r$) between labels and environmental features in the training set and evaluate standard OOD detection algorithms, including Maximum Softmax Probability (MSP), ODIN, Mahalanobis distance, and Energy-based scores.

Datasets

The study utilizes datasets specifically designed to highlight spurious correlations:

  • Waterbirds: Bird types (waterbird vs. landbird) correlated with backgrounds (water vs. land).
  • CelebA: Differentiating hair color (grey vs. non-grey), where "grey hair" is spuriously correlated with gender.
  • ColorMNIST: A variant of MNIST where digits are correlated with specific colors.
Training examples from the CelebA dataset showing the spurious correlation between hair color and gender.

For non-spurious OOD, benchmarks like SVHN, LSUN, and iSUN are used. For spurious OOD, the authors utilize subsets of the Places dataset, which contains backgrounds without the target objects.

Key Insights and Results

The Correlation Trap

As the spurious correlation ($r$) in the training set increases, OOD detection performance plummets. When $r=0.9$, the model is significantly worse at flagging OOD inputs than when $r=0.5$. On the Waterbirds task, the False Positive Rate (FPR95) for spurious OOD samples rose from 59.89% (at $r=0.5$) to 74.39% (at $r=0.9$).

Spurious OOD as "Hard" OOD

Detecting spurious OOD is much more difficult than detecting conventional OOD. Models frequently predict spurious OOD samples as the In-Distribution (ID) class that shares the same background with over 90% frequency. Theoretically, the authors prove that a model can achieve lower training risk by using a "shortcut" (the environmental feature) than by relying solely on invariant features, explaining why models "prefer" spurious correlations.

Feature Space vs. Output Space

Feature-based detection methods (like Mahalanobis distance) significantly outperform output-based methods (like MSP) for conventional OOD. For non-spurious OOD on Waterbirds, the Mahalanobis distance reduced the FPR95 by 46.73% compared to the standard MSP baseline. This is because the feature space preserves structural information about the data distribution that is lost in the final classification layer.

Conclusion

While feature-based methods help with conventional OOD, detecting "spurious OOD" remains an open and extremely challenging problem. Even the best methods struggle when the background is identical to the training set. This work highlights the need for training-time interventions, such as domain invariance learning, to produce more robust OOD detectors that are less reliant on environmental shortcuts. Future research should explore how complex real-world image features can be better modeled to bridge the gap in spurious OOD detection.

Summary updated

BibTeX
@inproceedings{ming2022impact,
  author = {Yifei Ming and Hang Yin and Yixuan Li},
  title = {{On the Impact of Spurious Correlation for Out-of-Distribution Detection}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2022},
  url = {https://openreview.net/forum?id=IryJVBEATZD},
}
Figure