You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Python library for Out-of-Distribution (OOD) Detection with Deep Neural Networks based on PyTorch.
The library provides:
Out-of-Distribution Detection Methods
Loss Functions
Datasets
Neural Network Architectures, as well as pre-trained weights
Data Augmentations
Useful Utilities
and is designed to be compatible with frameworks
like pytorch-lightning and
pytorch-segmentation-models.
The library also covers some methods from closely related fields, such as Open-Set Recognition, Novelty Detection,
Confidence Estimation and Anomaly Detection.
NOTE: An important convention adopted in pytorch-ood is that OOD detectors predict outlier scores
that should be larger for outliers than for inliers.
If you notice that the scores predicted by a detector do not match the formulas in the corresponding publication, we may have adjusted the score calculation to comply with this convention.
⏳ Quick Start
Load a WideResNet-40 model (used in major publications), pre-trained on CIFAR-10 with the Energy-Bounded Learning Loss [8] (weights from to original paper), and predict on some dataset data_loader using
Energy-based OOD Detection (EBO) [8], calculating the common metrics.
OOD data must be marked with labels < 0.
Evaluate detectors against common benchmarks, for example the OpenOOD v1.5 CIFAR benchmark.
All datasets will be downloaded automatically.
When evaluating several detectors on the same benchmark, cached logits
and pooled features can be reused across calls:
segmentation-models-pytorch to run the examples for anomaly segmentation
📝 Citing
If you use this project, please cite:
@inproceedings{kirchheim2022pytorch,
title={Pytorch-ood: A library for out-of-distribution detection based on pytorch},
author={Kirchheim, Konstantin and Filax, Marco and Ortmeier, Frank},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={4351--4360},
year={2022}
}
📦 Implemented
Detectors:
Objective Functions:
Objective Function
Description
Year
Ref
Objectosphere
Implementation of the paper Reducing Network Agnostophobia.
We encourage everyone to contribute to this project by adding implementations of OOD Detection methods, datasets etc,
or check the existing implementations for bugs.
🛡️ ️License
The code is licensed under Apache 2.0. We have taken care to make sure any third party code included or adapted has compatible (permissive) licenses such as MIT, BSD, etc.
The legal implications of using pre-trained models in commercial services are, to our knowledge, not fully understood.
🔗 References
[1]
Bendale, A., & Boult, T. E. (2016). Towards open set deep networks. CVPR.
[2]
(1, 2, 3) Liang, S., et al. (2017). Enhancing the reliability of out-of-distribution image detection in neural networks. ICLR.
[3]
Lee, K., et al. (2018). A simple unified framework for detecting out-of-distribution samples and adversarial attacks. NeurIPS.
[4]
Gal, Y., & Ghahramani, Z. (2016). Dropout as a bayesian approximation: Representing model uncertainty in deep learning. ICML.
[5]
Hendrycks, D., & Gimpel, K. (2016). A baseline for detecting misclassified and out-of-distribution examples in neural networks. ICLR.
[6]
Guo, C., et al. (2017). On calibration of modern neural networks. ICML.
Torralba, A., et al. (2007). 80 million tiny images: a large dataset for non-parametric object and scene recognition. IEEE Transactions on Pattern Analysis and Machine Learning.
de Campos, T. E., et al. (2009). Character recognition in natural images. In Proceedings of the International Conference on Computer Vision Theory and Applications (VISAPP).
Wei, et al. (2022) Mitigating Neural Network Overconfidence with Logit Normalization. ICML.
[47]
Liu, et al. (2025) Detecting Out-of-distribution through the Lens of Neural Collapse. CVPR.
[48]
Park, J., et al. (2023) Nearest Neighbor Guidance for Out-of-Distribution Detection. ICCV.
[49]
Lee, J., & AlRegib, G. (2020) Gradients as a Measure of Uncertainty in Neural Networks. ICIP.
[50]
Huang, R., et al. (2021) On the Importance of Gradients for Detecting Distributional Shifts in the Wild. NeurIPS.
[51]
Ren, J., et al. (2021) A Simple Fix to Mahalanobis Distance for Improving Near-OOD Detection. ArXiv.
[52]
Song, Y., et al. (2022) Rankfeat: Rank-1 Feature Removal for Out-of-Distribution Detection. NeurIPS.
[53]
Liu, X., et al. (2023) GEN: Pushing the Limits of Softmax-Based Out-of-Distribution Detection. CVPR.
[54]
Liu, L., & Qin, Y. (2023) Fast Decision Boundary based Out-of-Distribution Detector. ArXiv.
[55]
Bibas, K., Feder, M., & Hassner, T. (2021) Single Layer Predictive Normalized Maximum Likelihood for Out-of-Distribution Detection. ArXiv.
[56]
Xu, M., et al. (2023) VRA: Variational Rectified Activation for Out-of-Distribution Detection. ArXiv.
[57]
Liu, Y., et al. (2023) Neuron Activation Coverage: Rethinking Out-of-Distribution Detection and Generalization. ICLR.
[58]
Ming, Y., Cai, Z., Gu, J., Sun, Y., Li, W., & Li, Y. (2022) Delving into Out-of-Distribution Detection with Vision-Language Representations. NeurIPS. ArXiv.
[59]
(1, 2, 3) Zhang, J., Yang, J., et al. (2023) OpenOOD v1.5: Enhanced Benchmark for Out-of-Distribution Detection. DMLR. ArXiv.
[60]
(1, 2, 3) Gutbrod, M., Rauber, D., Nunes, D. W., & Palm, C. (2025) OpenMIBOOD: Open Medical Imaging Benchmarks for Out-Of-Distribution Detection. CVPR. ArXiv.