This repository contains the official implementation for the paper "Out-of-Distribution Detection with Relative Angles" (NeurIPS 2025).
Our work introduces ORA, a novel method for Out-of-Distribution (OOD) detection that leverages the concept of relative angles in the feature space. By analyzing the angular displacement of a test sample with respect to class prototypes, ORA provides a robust and effective signal for distinguishing in-distribution (ID) data from OOD data.
The project is structured into two main stages: feature extraction and OOD detection.
First, you need to extract and cache the features from the backbone models. This is done using feat_extract_all.py for ImageNet-based models and feat_extract_cifar.py for CIFAR-based models. These scripts will save the feature representations, logits, and labels to disk, which allows for faster experimentation in the next stage.
Once the features are cached, you can run the OOD detection experiments. The main scripts for this are:
run_imagenet_unified.py: For experiments on ImageNet and its variants.run_cifar.py: For experiments on CIFAR-10.
These scripts load the pre-computed features and apply various OOD detection methods to evaluate their performance.
The following backbone architectures are supported:
resnet18resnet18-supconresnet50resnet50-supconvitmobileconvnextconvnextpreswinswinpredeitdeitpredensenetevaclip
The following OOD datasets are supported for evaluation against ImageNet:
- iNaturalist (
inat) - SUN (
sun50) - Places (
places50) - Describable Textures Dataset (
dtd)
This repository includes implementations for several OOD detection methods, including our proposed method, ORA. Implementations can be seen in utils/ood_methods.py
The download.sh script is provided to download the necessary pretrained models (e.g., ResNets with SupCon loss) and the OOD datasets required to run the experiments.
If you find this work useful, please consider citing our paper:
@misc{demirel2025outofdistributiondetectionrelativeangles,
title={Out-of-Distribution Detection with Relative Angles},
author={Berker Demirel and Marco Fumero and Francesco Locatello},
year={2025},
eprint={2410.04525},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2410.04525},
}Feature extraction and metric computations are adapted from the official repository for the fDBD paper. We thank the authors for making their code public.
- fDBD Repository: https://github.com/litianliu/fDBD-OOD/tree/main