Home

Awesome

Publication Information

This repository accompanies the paper:

Keywords: out-of-distribution sample detection, outlier detection, anomaly detection, deep neural networks.

Bibtex:

@inproceedings{Shafaei2019,
    author = {Shafaei, Alireza and Schmidt, Mark and Little, James},
    booktitle = {BMVC},
    title = {{A Less Biased Evaluation of Out-of-distribution Sample Detectors}},
    year = {2019}
}

Introduction

Fig1

The problem of interest is out-of-distribution (OOD) sample detection. In our paper, we present an evaluation framework called OD-test for methods that address OOD sample detection. We show that the traditional evaluation strategy yields overly-optimistic results, hence the need for more reliable evaluation. In this repository, we implement the OD-test for image recognition problems with deep neural networks. You can replicate all the results of our paper here.

The OOD detection problem arises in settings where the input of the neural network in a deployed system is not guaranteed to follow a fixed distribution. OOD inputs can lead to unpredictable behaviour in neural network pipelines. For instance, the neural network might be trained to recognize the MNIST digits, but then when deployed, it might encounter a natural image which it has never seen. Counter-intuitively, the trained neural networks often fail silently and make over-confident predictions on previously unseen input. We need to develop methods that detect OOD samples to prevent unpredictable behaviour. Unfortunately, we cannot filter out these problematic instances by thresholding the output probability of the most likely class. In the above image, we show the output of several popular CNNs trained on ImageNet but tested on random benign images that do not belong to ImageNet.

The code in this repository allows

  1. Painless replication of all the results in the paper. You can run from scratch or use the pretrained models.
  2. Easy method development and testing for future work.
  3. Quickly adding more datasets for evaluation.

I have spent a long time refining this code. The final result is a modularized codebase that is reasonably efficient. I recommend that you take the time to understand the general architecture of the project before making substantial changes. I welcome pull-requests. In particular, if you wish to add a new method to the evaluation or improve a part of the code. You can ask questions in Issues.

What is next?

List of the Datasets

IndexNameTrainValidTestInput Dim#ClassesD1?
1MNIST(50,00010,000)10,00028x28 = 78410:heavy_check_mark:
2FashionMNIST(50,00010,000)10,00028x28 = 78410:heavy_check_mark:
3NotMNIST28x28 = 78410:x:
4CIFAR 10(40,00010,000)10,0003x32x32 = 3,07210:heavy_check_mark:
5CIFAR 100(40,00010,000)10,0003x32x32 = 3,072100:heavy_check_mark:
6TinyImagenet100,00010,00010,0003x64x64 = 12,288200:heavy_check_mark:
7STL105,000(4,0004,000)3x96x96 = 27,64810:heavy_check_mark:
8U(0,1)flexible:x:
9N(mu=0.5, sigma=0.25)flexible:x:

List of Implemented Methods

IndexNameShort DescriptionCode
1PbThreshold [1]A threshold on the maximum probability.link
2ScoreSVMA SVM on the logits (pre-softmax).link
3LogisticSVMA SVM on the logits of a network trained with k-way logistic loss function.link
4MCDropout [2]MC-Dropout evaluation over 7 samples followed by a threshold on the entropy of average prediction.link
5KNNSVMAn SVM on the sorted Euclidean distance to K-nearest-neighbours.link
6ODIN [3]A threshold on the scaled softmax outputs of the perturbed input.link
7AEThresholdA threshold on the autoencoder reconstruction error of the given input.link
8DeepEnsemble [4]Similar to MCDropout, except we average over the predictions of 5 networks that are trained independently with adversarial data augmentation.link
9PixelCNN++ [5]A threshold on the log-likelihood of each input.link
10OpenMax [6]Calibrated probability with additional unknown class and an SVM on top.link
11K-MNNSVM, K-BNNSVM, K-VNNSVMSimilar to KNNSVM, but uses the latent representation of different (variational)-autoencoders.link

Average Performance (Sept. 13, 2018)

Fig1

Setup

This project has been tested on:

We recommend installing Anaconda with Python 2.7 and Virtual Env.

Depending on the experiment being run, you may need up to 12 GBs of GPU memory. A single GPU suffices to run all the experiments.

Setting up the Environment

The setup script creates a workspace folder within which all the subsequent project files will be put. To get started, you must first run the setup script.

> cd <root_folder>
> python setup/setup.py

The setup script will create a virtual environment at workspace/env and will install the required packages from requirements.txt. After a successful setup, you can activate the environment using:

source workspace/env/bin/activate

You must run all the scripts within the generated environment.

Visualization

In this project we use visdom for visualization mid-training. We use seaborn to generate the figures in the paper. I wrote this code assuming that visdom is available for visualization at first. I then rewrote the code to make it functional without visdom as well. However, some parts of the code may still require visdom to be accessible. To be on the safe side, I recommend having visdom in the background just in case until I make sure the entire project would function correctly without visdom as well. (pull request to resolve this issue are welcomed!)

In a new terminal tab run this:

> cd <root_folder>
> bash launch_visdom.sh

If you execute the code on a remote server, but you want to run visdom on your local machine, you can do a remote (reverse) port forwarding for port 8097 to your machine with SSH like this:

# Run this from the local machine to connect to the remote machine which will execute the scripts.
ssh -R 8097:localhost:8097 user@remote-machine

With this you can have a single visdom running locally, but having multiple machines reporting to the same visdom.

References

  1. D. Hendrycks and K. Gimpel, “A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networks,” ICLR, 2017.
  2. Y. Gal and Z. Ghahramani, “Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning,” in ICML, 2016.
  3. S. Liang, Y. Li, and R. Srikant, “Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networks,” ICLR, 2018.
  4. B. Lakshminarayanan, A. Pritzel, and C. Blundell, “Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles,” in NIPS, 2017.
  5. T. Salimans, A. Karpathy, X. Chen, and D. P. Kingma, “Pixelcnn++: Improving the pixelcnn with discretized logistic mixture likelihood and other modifications,” ICLR, 2017.
  6. A. Bendale and T. E. Boult, “Towards Open Set Deep Networks,” in CVPR, 2016.