Home

Awesome

Nearest Neighbor Guidance for Out-of-Distribution Detection

This is the official repository of the ICCV2023 paper Nearest Neighbor Guidance for Out-of-Distribution Detection (arxiv)

Setup

Conda

The experiments have been conducted on the following settings:

The conda environment is installed by

conda create -n nnguide python=3.8.13

and then on the nnguide conda environment, the required packages are installed by

chmod +x install_packages.sh
./install_packages.sh

Dataset

To set up dataset folder structures, refer to README.md in the ./dataloaders folder.

1. Download ImageNet-1k:

Download ILSVRC2012_img_train.tar and ILSVRC2012_img_val.tar from the official ImageNet website. And use ./dataloaders/assets/extract_ILSVRC.sh to unzip the zip files.

2. Download iNaturalist, SUN, Places, Textures, OpenImage-O OOD datasets:

To download iNaturalist, SUN, and Places

wget http://pages.cs.wisc.edu/~huangrui/imagenet_ood_dataset/iNaturalist.tar.gz
wget http://pages.cs.wisc.edu/~huangrui/imagenet_ood_dataset/SUN.tar.gz
wget http://pages.cs.wisc.edu/~huangrui/imagenet_ood_dataset/Places.tar.gz

Download Textures from the official website. Download OpenImage-O from the official website.

Debug: CIFAR, SVHN

The datasets CIFAR10/100 and SVHN are provided only for the debugging purpose.

Pretrained models

Download resnet50-supcon.pt from the link and put it in the directory pretrained_models as ./pretrained_models/resnet50-supcon.py.

To fully reproduce the reported results, download saved_model_outputs from the link and save it with the path ./saved_model_outputs.

Run Experiments

To run experiments, execute

chmod +x run.sh
./run.sh

Acknowledgements

Parts of our codebase have been adopted from the official repositories for KNN-OOD and VIM, and we benefited from the pretrained weights made available through these sources. Our code style is largely inspired by OpenOOD.

Citation

If you find our repository useful for your research, please consider citing our paper:

@inproceedings{park2023nearest,
  title={Nearest Neighbor Guidance for Out-of-Distribution Detection},
  author={Park, Jaewoo and Jung, Yoon Gyo and Teoh, Andrew Beng Jin},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  pages={1686--1695},
  year={2023}
}