Skip to content

An implementation of the Residual Flow algorithm for out-of-distribution detection.

Notifications You must be signed in to change notification settings

EvZissel/Residual-Flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An implementation of the Residual Flow algorithm for out-of-distribution detection.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages