Giter Site home page Giter Site logo

residual-flow's Introduction

Deep Residual Flow for Out of Distribution Detection

An implementation of the Residual Flow algorithm for out-of-distribution detection [arXiv] . Some code was adopted from deep_Mahalanobis_detector and RealNVP.

Citing Residual Flow for OOD Detection

E. Zisselman, A. Tamar. "Deep Residual Flow for Out of Distribution Detection". CVPR 2020.
@InProceedings{Zisselman_2020_CVPR,
    author = {Zisselman, Ev and Tamar, Aviv},
    title = {Deep Residual Flow for Out of Distribution Detection},
    booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
    month = {June},
    year = {2020}
}

Dependencies

Tested on Ubuntu Linux 18.04.04 and Python 3.7, and requires the following dependencies:

Links for downloading Out-of-Distribution Datasets

The datasets from odin-pytorch:

are to be placed in ./data/.

Links for downloading Pre-trained Classification Networks

The pre-trained neural networks are from deep_Mahalanobis_detector:

  1. DenseNet trained on CIFAR-10, CIFAR-100 and SVHN.

  2. ResNet trained on CIFAR-10, CIFAR-100 and SVHN.

To be placed in ./pre_trained/.

Links for downloading Pre-trained Residual Flow Networks

We provide six pre-trained residual flow networks for OOD detection for ResNet and DenseNet:

  1. DenseNet trained on CIFAR-10, CIFAR-100 and SVHN.
  1. ResNet trained on CIFAR-10, CIFAR-100 and SVHN.

To be placed in ./output/.

Detecting Out-of-Distribution Samples (validate on OOD samples)

Example usage of residual flow targeting ResNet trained on CIFAR-10.
Settings: 1x GPU (index 0)

1. Feature extraction

# extract feature activations from classification network 
python Residual_flow_prepare.py --dataset cifar10 --net_type resnet --gpu 0

2. Residual Flow training (optional)

Place the pre-trained residual flow networks (ResNet, CIFAR-10) in ./output/ or train the networks using the following:

Note: Each layer is trained individually using the flag --layer n where 'n' is the layer index [0..N]

# (optional - you may use the pre-trained networks above) 

# Residual Flow training - trained per target network layer [0..N]
#                          where N = 3 for DenseNet and N = 4 for ResNet 
python Residual_flow_train.py --num_iter 2000 --net_type resnet --dataset cifar10 --layer 0 --gpu 0

3. Extract Residual Flow score for OOD detection

python Residual_flow_test_processing.py --net_type resnet --dataset cifar10

# (optional) comparison with Mahalanobis detector
python OOD_Generate_Mahalanobis.py --dataset cifar10 --net_type resnet --gpu 0

4. Train a simple regression detector

python OOD_Regression_Residual_flow.py --net_type resnet

# (optional) comparison with Mahalanobis detector
python OOD_Regression_Mahalanobis.py --net_type resnet

Detecting Out-of-Distribution Samples (validate on FGSM samples)

1. Feature extraction

# generate the adversarial samples
python ADV_Samples_FGSM.py

# extract feature activations from classification network 
python Residual_flow_prepare.py --dataset cifar10 --net_type resnet --gpu 0 --validation_src FGSM

2. Residual Flow training (optional)

Place the pre-trained residual flow networks (ResNet, CIFAR-10) in ./output/ or train the networks using the following:

Note: Each layer is trained individually using the flag --layer n where 'n' is the layer index [0..N]

# (optional - you may use the pre-trained networks above) 

# Residual Flow training - trained per target network layer [0..N]
#                          where N = 3 for DenseNet and N = 4 for ResNet 
python Residual_flow_train.py --num_iter 2000 --net_type resnet --dataset cifar10 --layer 0 --gpu 0

3. Extract Residual Flow score for OOD detection

python Residual_flow_test_processing.py --net_type resnet --dataset cifar10 --validation_src FGSM

# (optional) comparison with Mahalanobis detector
python ADV_Generate_Mahalanobis.py.py --dataset cifar10 --net_type resnet --gpu 0

4. Train a simple regression detector

python OOD_Regression_Residual_flow_FGSM_validation.py --net_type resnet

# (optional) comparison with Mahalanobis detector
python OOD_Regression_Mahalanobis_FGSM_validation.py --net_type resnet

residual-flow's People

Contributors

evzissel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.