Home

Awesome

Generalized-ODIN-TF

TensorFlow 2 implementation of the paper Generalized ODIN: Detecting Out-of-distribution Image without Learning from Out-of-distribution Data.

Detecting out-of-distribution (OOD) data is a challenging problem for deep neural networks to tackle especially when they weren't exposed to OOD data. One way to solve this is to expose networks to OOD data during its training. But this can become a brittle approach when the space of the OOD data gets larger for a network. What if we present a network with OOD data it hasn't been exposed to during its training?

Therefore, we need a better way to deal with the problem. Generalized ODIN (Out-of-DIstribution detector for Neural networks) is a good first step toward that.

Organization of the files

├── Baseline.ipynb: Trains a ResNet20 model on the CIFAR-10 dataset (in-distribution dataset). We will consider this to be our baseline model.
├── Calculate_Epsilon.ipynb: Searches for the best epsilon (perturbation magnitude) as proposed in the paper. 
├── Evaluation_OOD.ipynb: Evaluates the baseline model as well as the Generalized ODIN model.
├── Generalized_ODIN.ipynb: Trains the Generalized ODIN model on the CIFAR-10 dataset. 
└── scripts
    ├── metrics.py: Utilities for evalutation metrics (AUROC and TNR@TPR95)
    ├── resnet20.py: ResNet20 model utilities. 
    └── resnet20_odin.py: ResNet20 with Generalized ODIN utilities. 

TNR: True Negative Rate, TPR: True Positive Rate

Task of interest

Train a model on the CIFAR-10 dataset (in-distribution dataset) in a way that maximizes its capability to detect OOD samples. This project uses the SVHN dataset for the OOD samples.

Main differences in the implementation

Results

<p align="center">
Train Top-1Test Top-1AUROCTNR@TPR95
Generalized ODIN99.4691.4292.1554.18
Baseline99.5890.791.1440.53
</p>

How to use these models to detect OOD samples?

Take the output of the ODIN and see if it crosses a threshold. If it does then the corresponding samples IID otherwise OOD.

Here's an advice I got from Yen-Chang Hsu (first author of the paper):

The selection of thresholds is application-dependent. It will still rely on having a validation set (which includes in-distribution and optionally OOD data) for an application. One way is to select the threshold is pick one that makes TPR=95%.

Pre-trained models

Available here.

Acknowledgements

Paper citation

@INPROCEEDINGS{9156473,
  author={Y. -C. {Hsu} and Y. {Shen} and H. {Jin} and Z. {Kira}},
  booktitle={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, 
  title={Generalized ODIN: Detecting Out-of-Distribution Image Without Learning From Out-of-Distribution Data}, 
  year={2020},
  volume={},
  number={},
  pages={10948-10957},
  doi={10.1109/CVPR42600.2020.01096}}