This is an pytorch implementation of Unsupervised Out-of-Distribution Detection by Maximum Classifier Discrepancy.
- Python 3.7
- PyTorch 1.1.0
- torchvision 0.3.0
- progress
- matplotlib
- numpy
Download five out-of-distributin datasets provided by ODIN:
Here is an example code of downloading Tiny-ImageNet (crop) dataset. In the root directory, run
mkdir data
cd data
wget https://www.dropbox.com/s/avgm2u562itwpkl/Imagenet.tar.gz
tar -xvzf Imagenet.tar.gz
cd ..
We provide download links of cifar10/100 pre-trained models.
In the root directory, run
mkdir pretrained
cd pretrained
wget https://www.dropbox.com/s/qjitycxijexzp8y/pretrained.zip
unzip pretrained.zip
cd ..
Finetune DenseNet on CIFAR-10 as ID and TinyImageNet as OOD.
python train.py -c checkpoints/cifar10_Imagenet_ckpt --gpu 0 --resume pretrained/cifar10_dense.pth.tar --out-dataset Imagenet
Trained model will be saved at checkpoints/cifar10_Imagenet_ckpt
.
python train_all.py --gpu 0
This script will finetune models of DenseNet/WideResNet on CIFAR-10/100 as ID and five other datasets as OOD which results in 20 models.
Trained model will be saved at checkpoints
.
For example, to test DenseNet-BC trained on CIFAR-10 where TinyImageNet (crop) is the out-of-distribution dataset, please run
python test.py --result checkpoints/cifar10_Imagenet_ckpt
- [1]: Q. Yu and K. Aizawa. "Unsupervised Out-of-Distribution Detection by Maximum Classifier Discrepancy", in ICCV, 2019.
- [2]: S. Liang, Y. Li and R. Srikant. "Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networks", in ICLR, 2018.