NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Rethinking Out-of-distribution (OOD) Detection: Masked Image Modeling is All You Need

Jingyao Li, Pengguang Chen, Zexin He, Shaozuo Yu, Shu Liu, Jiaya Jia · DOI

Abstract

Out-of-distribution (OOD) detection is a fundamental challenge in machine learning, ensuring that models can identify inputs that deviate from their training distribution. Traditional approaches have largely focused on recognition-based methods, which are prone to learning discriminative "shortcuts" that fail on near-distribution samples. This paper presents MOOD (Masked image mOdeling for OOD Detection), a novel framework that utilizes Masked Image Modeling (MIM) to capture the intrinsic geometry and structural properties of data. By prioritizing reconstruction over classification, MOOD establishes new state-of-the-art benchmarks in one-class, multi-class, and near-distribution OOD tasks, even outperforming methods that utilize outlier exposure during training.

Introduction

The ability of a machine learning model to "know what it doesn't know" is essential for safety-critical applications. Out-of-distribution (OOD) detection aims to flag test samples that do not belong to the training distribution. Historically, research has focused on improving classification-based models, using their confidence scores or feature space clusters to identify anomalies. However, these "recognition-based" methods often suffer from a reliance on shortcuts—minimal features sufficient for classification but insufficient for understanding the full data distribution. For instance, a model might identify a cat solely by its ears, leading it to misclassify a semantically similar but distinct animal as "in-distribution."

The MOOD Framework

To address these limitations, the researchers propose MOOD (Masked image mOdeling for OOD Detection). The core philosophy of MOOD is that reconstruction is a more powerful prior for OOD detection than recognition.

Masked Image Modeling (MIM)

MOOD utilizes a Vision Transformer (ViT) architecture trained on a Masked Image Modeling task. Similar to the masked language modeling used in BERT, the model is tasked with reconstructing missing patches of an input image. To succeed at this task, the model must develop a comprehensive, pixel-level understanding of the data's structure, texture, and geometry, rather than just identifying discriminative labels.

Strategic Fine-Tuning and Label Smoothing

The framework involves pre-training on a large-scale dataset (ImageNet-21k) followed by fine-tuning on the specific In-Distribution (ID) dataset. A key innovation in the MOOD training process is the application of label smoothing in one-class OOD tasks. While typically used to improve generalization, label smoothing here prevents the model from reaching a state of overconfidence. This forces the model to continuously refine its internal representation of the ID distribution, even after the primary classification task appears solved.

Detection via Mahalanobis Distance

For the inference phase, MOOD employs the Mahalanobis distance to score test samples. By calculating the distance between a test sample's features and the mean features of the training set, the model can effectively flag samples that fall outside the learned manifold as OOD.

Experimental Evaluation

The researchers evaluated MOOD across a diverse range of benchmarks, including CIFAR-10, CIFAR-100, and ImageNet-1k as In-Distribution sets, with SVHN, LSUN, and Places365 as OOD sets.

Performance Metrics

MOOD demonstrated significant improvements over existing state-of-the-art (SOTA) methods:

  • One-Class OOD: MOOD achieved a 5.7% improvement in AUROC over the previous leading method, CSI.
  • Multi-Class OOD: The framework outperformed SSD+ by 3.0%.
  • Near-Distribution Challenges: In the difficult task of distinguishing CIFAR-10 from CIFAR-100, MOOD reached an AUROC of 98.3%, surpassing specialized ViT-based models by 2.1%.

Comparison with Outlier Exposure

One of the most striking findings is that MOOD outperforms models trained with "Outlier Exposure" (OE). OE methods involve training the model on a subset of real OOD samples to help it define boundaries. MOOD, despite having zero exposure to OOD samples during training, outperformed "10-shot" OE methods (99.41% vs 99.29% AUROC). This suggests that a sufficiently deep understanding of the "known" is more robust than a superficial exposure to the "unknown."

Discussion and Limitations

The success of MOOD highlights a paradigm shift: reconstruction tasks provide a more "efficacious prior" for anomaly detection than classification tasks. However, the method is not without challenges. The use of Vision Transformers and MIM is computationally intensive compared to standard ResNet architectures. Furthermore, the performance is currently dependent on high-quality pre-training on datasets like ImageNet-21k, which may limit its immediate applicability in niche domains like medical imaging where such data is scarce. Finally, the choice of distance metric remains a critical factor, indicating that the scoring mechanism itself is a fertile ground for future optimization.

Conclusion

MOOD demonstrates that Masked Image Modeling is a highly effective foundation for OOD detection. By moving away from label-based shortcuts and toward a generative understanding of data, MOOD provides a more principled approach to identifying the boundaries of a model's knowledge. This work paves the way for more reliable and self-aware AI systems in complex, real-world environments.

Summary updated

BibTeX
@misc{li2023rethinking,
  author = {Jingyao Li and Pengguang Chen and Zexin He and Shaozuo Yu and Shu Liu and Jiaya Jia},
  title = {{Rethinking Out-of-distribution (OOD) Detection: Masked Image Modeling is All You Need}},
  year = {2023},
  eprint = {2302.02615},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2302.02615},
}
Figure