This is the official repository of the ICCV2023 paper Nearest Neighbor Guidance for Out-of-Distribution Detection (arxiv)
The experiments have been conducted on the following settings:
- Ubuntu 20.04
- CUDA 11.3
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
To set up dataset folder structures, refer to README.md
in the ./dataloaders
folder.
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.
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.
The datasets CIFAR10/100 and SVHN are provided only for the debugging purpose.
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
.
To run experiments, execute
chmod +x run.sh
./run.sh
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.
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}
}