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, Shaozuo Yu, Zexin He, Shu Liu, Jiaya Jia

TL;DR

Standard out-of-distribution (OOD) detection methods rely on classification or contrastive learning, which often learn superficial "shortcuts" instead of the true underlying data distribution. This paper introduces MOOD, demonstrating that simply using a reconstruction-based pretext task—Masked Image Modeling (MIM)—allows Vision Transformers to learn intrinsic data distributions, achieving state-of-the-art OOD detection performance without ever needing to see an outlier during training.

What Problem Does This Paper Address?

Out-of-distribution (OOD) detection is crucial for safety-critical AI applications like autonomous driving, fraud detection, and medical diagnosis. A reliable system must not only make accurate predictions on known data (in-distribution, or ID) but also safely reject unknown or anomalous inputs (OOD).

Traditionally, models learn ID features via classification or contrastive learning. However, classification networks are notorious for taking shortcuts—focusing only on the minimal distinguishing patterns needed to separate classes rather than understanding the holistic data distribution. If an OOD sample happens to share these shortcut features, the model easily misclassifies it as ID. Furthermore, many top-performing OOD algorithms rely on "outlier exposure" (training with a few example OOD images), which fundamentally violates the real-world goal of detecting entirely unknown anomalies.

Methods

The authors propose MOOD (Masked image modeling for OOD Detection). Instead of using a recognition-based pretext task, they leverage Masked Image Modeling (MIM) using a Vision Transformer (ViT).

  1. MIM Pre-training: Images are split into patches, and a large portion of them are randomly masked. The ViT is trained to reconstruct the missing patches using tokens from a discrete VAE (Visual Autoencoder) as labels. This forces the network to learn pixel-level, intrinsic data distributions rather than just class boundaries.
  2. Fine-tuning: The model is then fine-tuned on the target ID dataset. For one-class OOD detection (where only one category is considered "normal"), they introduce label smoothing. This counter-intuitive trick keeps the training loss above zero even when classification accuracy hits 100%, forcing the model to continuously refine its internal representations.
  3. OOD Scoring: During inference, features are extracted from the trained ViT, and the Mahalanobis distance is calculated to determine how far a test sample lies from the ID data center.

Datasets

The authors evaluated their approach on standard OOD benchmarks:

  • In-Distribution (ID) Datasets: CIFAR-10, CIFAR-100 (including super-classes), ImageNet-30, and ImageNet-1k.
  • Out-of-Distribution (OOD) Datasets: SVHN, LSUN, Places365, Textures, iNaturalist, SUN, and various fine-grained datasets (e.g., Stanford Dogs, Oxford Pets, Food-101, Caltech-256, and Describable Textures Dataset).

No new datasets were introduced, ensuring a direct and fair comparison with prior work.

Key Insights and Ideas

  • Reconstruction Beats Classification for OOD: Generative/reconstruction tasks prevent the model from taking classification shortcuts. By forcing the network to predict missing pixels, it develops a much more robust understanding of what "normal" data looks like.
  • Zero-Shot Beats Few-Shot Outlier Exposure: Remarkably, MOOD (which uses 0 OOD samples during training) outperforms existing state-of-the-art models that are explicitly exposed to 10 OOD samples per class. This proves that a strong pretext task eliminates the need for risky outlier exposure.
  • Label Smoothing as an Optimization Driver: In one-class fine-tuning, labels are uniform, which usually halts optimization. Label smoothing keeps the loss gradient alive, allowing the model to continue learning useful features from the ID dataset.

Key Results

MOOD achieves massive improvements across four core OOD tasks, as summarized in Figure 1:

Figure 1. Performance of MOOD compared with current SOTA (indicated by ‘*’) on four OOD detection tasks: (a) one-class OOD detection; (b) multi-class detection; (c) near-distribution detection; and (d) few-shot outlier exposure OOD detection.
  • One-class OOD detection: Boosts AUROC by 5.7% over the previous SOTA (CSI), reaching 94.9%.
  • Multi-class OOD detection: Outperforms SSD+ by 3.0%, reaching 97.6%.
  • Near-distribution OOD detection: Achieves 98.3% AUROC, beating the previous R50+ViT SOTA by 2.1%.
  • Few-shot Outlier Exposure: Reaches 99.41% AUROC, outperforming 10-shot outlier exposure methods (99.29%) despite using zero outlier samples.

Qualitatively, MOOD significantly increases the separation between ID and OOD probability distributions (Figure 2) and drastically reduces the number of mistakenly classified near-distribution samples (Figure 3).

Figure 2. Line chart to illustrate the relation between the proba- bility distribution of test samples and OOD detection metrics on (a) CIFAR-10, (b) CIFAR-100, and (c) ImageNet-30. Each line in the sub-figures represents an OOD or ID dataset. We compare three OOD detection approaches, including baseline OOD detec- tion, SSD+ (current SOTA, [53] ), and our proposed MOOD. The baseline OOD detection takes the maximum softmax probabilities as its OOD detection metric, while SSD+ and MOOD both use the Mahalanobis distance as their metrics.
Figure 3. Near-distribution OOD detection (multi-class). Num- ber of some mistakenly-classified OOD samples (when TPR = 95%). These samples are wrongly taken as ID samples by the cur- rent SOTA of SSD+ [53] in multi-class detection on CIFAR-10. ‘*’ indicates SOTA.

Limitations and Future Work

While the paper demonstrates outstanding performance, a few limitations are apparent:

  • Computational Overhead: The method relies heavily on large-scale pre-training (ImageNet-21k) and Vision Transformers (ViT), which are computationally heavier and slower to train/run than smaller CNN-based OOD detectors.
  • Future Directions: The authors suggest that future work could explore optimizing the computational efficiency of MIM-based OOD detection or adapting this reconstruction-based paradigm to other modalities like text or audio.

Summary updated

BibTeX
@misc{li2023rethinking,
  author = {Jingyao Li and Pengguang Chen and Shaozuo Yu and Zexin He 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