This is the code repository for TAPS.
We use python version 3.9 and pytorch 1.13.1, which can be installed in a conda environment as follows:
conda create -y --name TAPS python=3.9
conda activate TAPS
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidiaTo install further requirements please run
pip install -r requirements.txtTo train our models for MNIST, CIFAR-10, and TinyImageNet using both TAPS and STAPS, please use the commands provided in:
./scripts/train_mnist
./scripts/train_cifar
./scripts/train_tinyimagenetBefore training with TinyImagenet, make sure to download the dataset by running
bash ./scripts/tinyimagenet_download.shWe combine IBP, CROWN-IBP and MN-BaB for certification. To set up certification, please install MN-BaB as (note that you might need a ssh key in your GitHub setting to clone the repository if you get permission denied error)
git clone --branch SABR_ready --recurse-submodules https://github.com/eth-sri/mn-bab
cd mn-bab
source setup.sh
cd ..Now use the commands provided in ./scripts/mnbab_certify to run certification.
We release all the models reported in our paper in the following link.
For every model, we include the complete training log (monitor.json), training arguments (./train_args.json), certification log (./complete_cert.json), and certification arguments (./cert_args.json) in the corresponding directories.
Note that all the following codes are for illustrative purpose since the processing of data directory is not necessarily aligned. If the model is not explicitly provided, it refers to the final models we released.
- Figure 1, 5, 6 and 9:
theory_TAPS_approximation.pycomputes the estimated margin ($\max_{i \ne c} y_i - y_c$ ) via IBP (sound over-approximation), PGD (margin attack with 3 restarts), MILP (exact solution but slow), SABR (SOTA method, unsound), TAPS (this work, unsound but precise) over models trained with these methods. The corresponding command is included in./scripts/theory_TAPS_approximationand the results are included in theory_approximation../theory_approximation/mnist/eps0.05/modelscontains the models (the target$\epsilon$ is 0.05) and./theory_approximation/mnist/eps0.05/lower_boundcontains the results.plot_TAPS_approximation.pycontains the plotting code. - Table 10:
GoF_computation.pycomputes Table 10 from the trained final models. It retrieved TAPS estimated robust accuracy frommonitor.jsonand MN-BaB certified accuracy fromcomplete_cert.jsonand then computes the difference. - Figure 10 and 11:
train_quality_measure.pyloads each model and test under various splits. The corresponding command is included in./scripts/measure_train_quality.
Here we present the functionality of the core files.
-
mix_train.pyis the main file for training models. -
args_factory.pydefines the arguments. -
loaders.pydefines the pipeline to process data and return dataloaders. -
attacks.pydefines the adversarial attacks. -
torch_model_wrapper.pywraps IBP, PGD, SABR, TAPS and STAPS implementation into a consistent format and is called by other files. -
regularization.pydefines$L_1$ and fast regularization used in IBP. -
utils.pycontains utility functions, including the definition of$\epsilon$ -scheduler. -
PARC_networks.pydefines the network structure. The most important one iscnn_7layer_bn, which is also used by SABR and fast-IBP paper.
- Copyright (c) 2023 Secure, Reliable, and Intelligent Systems Lab (SRI), Department of Computer Science ETH Zurich
- Licensed under the Apache License