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

MOODv2: Masked Image Modeling for Out-of-Distribution Detection

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

Abstract

Out-of-Distribution (OOD) detection is a fundamental requirement for the reliable deployment of vision systems in open-world environments. Existing approaches primarily rely on classification-based or contrastive learning, which are prone to "shortcut learning"—relying on sparse, discriminative features rather than a comprehensive understanding of the data. We present MOODv2, a framework that leverages Masked Image Modeling (MIM) as a self-supervised pretext task for OOD detection. By prioritizing image reconstruction over simple label recognition, MOODv2 captures deep, pixel-level representations of in-distribution data. Our method achieves a state-of-the-art AUROC of 95.68% on ImageNet and 99.98% on CIFAR-10, demonstrating that reconstruction-based learning provides a more robust signal for identifying unknown inputs.

Introduction

A critical failure mode for modern AI occurs when a model encounters "Out-of-Distribution" (OOD) data—inputs that fall outside its training distribution. Ideally, a safe system should flag these as "unknown." However, standard training paradigms often encourage models to find the simplest path to minimize loss, a phenomenon known as shortcut learning. For instance, a model might identify a "cat" solely by the presence of pointed ears, leading it to misclassify a fox with high confidence.

MOODv2 addresses this by shifting the detection paradigm. Instead of teaching a model to categorize, we teach it to rebuild. This holistic approach ensures the model understands the global structure and local details of the target distribution, making it much harder to fool with OOD samples that lack these learned structural properties.

Methodology: From Recognition to Reconstruction

The core innovation of MOODv2 is the use of Masked Image Modeling (MIM) as the primary learning objective.

The MOODv2 Pipeline

  1. Pre-training: A vision encoder (e.g., Vision Transformer) is pre-trained using MIM. During this phase, random patches of an image are masked, and the network is tasked with reconstructing the missing pixels.
  2. Fine-tuning: The backbone is subsequently fine-tuned on the specific In-Distribution (ID) dataset to specialize its representations.
  3. OOD Scoring: To identify OOD samples, MOODv2 employs the Virtual-logit Matching (ViM) score. This function integrates information from both the high-dimensional feature space and the final classification logits.
Comparison between classification-based and reconstruction-based OOD detection methods.

By forcing the model to reconstruct the entire image, it develops a "visual discrepancy" signal: it can perfectly reconstruct ID images but produces distorted or blurry outputs for OOD images.

Experimental Evaluation

We evaluated MOODv2 using CIFAR-10 and ImageNet-1K as In-Distribution (ID) datasets. To ensure rigorous testing, we utilized several challenging OOD benchmarks:

  • OpenImage-O: Large-scale diverse images.
  • Texture: Natural textures distinct from ImageNet classes.
  • iNaturalist: Fine-grained biological species.
  • ImageNet-O: Adversarial images specifically designed to trigger misclassification.

Results and Discussion

MOODv2 sets a new performance benchmark across all tested datasets. On ImageNet, it improves the AUROC from approximately 81% (standard ViT) to 95.68%, representing a 14.30% absolute gain. On CIFAR-10, the model achieves near-perfect detection with a 99.98% AUROC.

Performance comparison of MOODv2 vs MOODv1 on ImageNet and CIFAR-10 benchmarks.

Score Function Agnosticism

An important finding is that the quality of MIM-learned features reduces the sensitivity to the specific mathematical scoring function used (e.g., MSP, Energy, Mahalanobis). While classification-based models show high variance in performance depending on the score function, MOODv2 remains stable. This suggests that the bottleneck in OOD detection has historically been the representation itself, rather than the scoring logic.

Conclusion

MOODv2 demonstrates that reconstruction-based pretext tasks are significantly more effective for OOD detection than traditional classification objectives. By avoiding shortcut learning and forcing a holistic understanding of image data, MIM provides a robust foundation for safety-critical vision applications. Future work will explore the scalability of this approach to other modalities such as video and 3D point clouds.

Summary updated

BibTeX
@article{li2024moodv,
  author = {Jingyao Li and Pengguang Chen and Shaozuo Yu and Shu Liu and Jiaya Jia},
  title = {{MOODv2: Masked Image Modeling for Out-of-Distribution Detection}},
  journal = {IEEE Trans. Pattern Anal. Mach. Intell.},
  year = {2024},
  doi = {10.1109/tpami.2024.3412004},
}
Figure