This repository contains the code used for the paper Understanding and mitigating exploding inverses in invertible neural networks.
This code is based on jhjacobsen/fully-invertible-revnet, y0ast/Glow-PyTorch, plucas14/pytorch-glow, and rtqichen/residual-flows.
- Python 3.7.x
- PyTorch 1.1.0
First, create a conda environment with the necessary packages:
conda create -n inn-env python=3.7
source activate inn-env
conda install pytorch=1.1.0 cuda80 -c pytorch
conda install torchvision -c pytorch
pip install -r requirements.txt
The following commands should be run from inside the ood-pretrained
folder.
First, download the OOD datasets:
./download_ood_data.sh
Download the pre-trained Glow model used in the y0ast/Glow-PyTorch repository:
./download_pretrained_glow.sh
Then, run the OOD evaluation:
python glow_ood_eval.py
The following commands must be run within the ood-pretrained/residual-flow
folder.
First, download the pre-trained Residal Flow model from the repository rtqichen/residual-flows:
./download_pretrained_resflow.sh
Then, run the OOD evaluation:
python resflow_ood_eval.py
Details on how to set up and run the invertibility attack are provided in the README inside the inv-attacks-and-2D-flows
folder.
For details on how to train and analyze stability properties of flows, as well as how to train a FlowGAN, see the README inside the glow
folder.
To train regularized and unregularized Glow models on the toy 2D regression task, run the following commands from inside the toy-2d-regression
folder:
python toy_2d_regression.py
python toy_2d_regression.py --nf_coeff=1e-6
To train an INN classifier, run any of the following commands from inside the classification
folder:
To train an unregularized model that becomes numerically non-invertible, you can run:
Unregularized Affine Glow with 1x1 Convolutions
python train_inn_classifier.py \
--coupling=affine \
--permutation=conv \
--zero_init \
--use_prior \
--use_actnorm \
--no_inverse_svd \
--save_dir=saves/affine_conv
Unregularized Affine Glow with Shuffle Permutations
python train_inn_classifier.py \
--coupling=affine \
--permutation=shuffle \
--zero_init \
--use_prior \
--use_actnorm \
--no_inverse_svd \
--save_dir=saves/affine_shuffle
Affine Glow with 1x1 Convolutions, NF coefficient 1e-5
python train_inn_classifier.py \
--coupling=affine \
--permutation=conv \
--zero_init \
--use_prior \
--use_actnorm \
--no_inverse_svd \
--nf_coeff=1e-5 \
--save_dir=saves/affine_conv
Affine Glow with Shuffle Permutations, NF coefficient 1e-4
python train_inn_classifier.py \
--coupling=affine \
--permutation=shuffle \
--zero_init \
--use_prior \
--use_actnorm \
--no_inverse_svd \
--nf_coeff=1e-5 \
--save_dir=saves/affine_shuffle
Affine Glow with 1x1 Convolutions, FD coefficient 1e-4
python train_inn_classifier.py \
--coupling=affine \
--permutation=conv \
--zero_init \
--use_prior \
--use_actnorm \
--no_inverse_svd \
--fd_coeff=1e-4 \
--fd_inv_coeff=1e-4 \
--regularize_every=10 \
--mem_saving \
--save_dir=saves/affine_conv
Affine Glow with Shuffle Permutations, FD coefficient 1e-4
python train_inn_classifier.py \
--coupling=affine \
--permutation=shuffle \
--zero_init \
--use_prior \
--use_actnorm \
--no_inverse_svd \
--fd_coeff=1e-4 \
--fd_inv_coeff=1e-4 \
--regularize_every=10 \
--mem_saving \
--save_dir=saves/affine_shuffle
If you find this repository useful, please cite:
Jens Behrmann*, Paul Vicol*, Kuan-Chieh Wang*, Roger Grosse, Jörn-Henrik Jacobsen. Understanding and mitigating exploding inverses in invertible neural networks, 2020.
@article{innexploding2020,
title={Understanding and mitigating exploding inverses in invertible neural networks},
author={Jens Behrmann and Paul Vicol and Kuan-Chieh Wang and Roger Grosse and Jörn-Henrik Jacobsen},
journal={arXiv preprint arXiv:2006.09347},
year={2020}
}