Home

Awesome

Free Adversarial Training

This repository belongs to the Free Adversarial Training paper. The implementation is inspired by CIFAR10 Adversarial Example Challenge so to them we give the credit. This repo is for the CIFAR-10 and CIFAR-100 datasets and is in Tensorflow. Our Free-m models can acheive comparable performance with conventional PGD adversarial training at a fraction of the time.

News!: We have released our ImageNet implementation of Free adversarial training in Pytorch !

CIFAR-10 WRN 32-10 (L-inf epsilon=8):
ModelNaturalPGD-100CW-10010 restart PGD-20train-time (min)
Natrual95.010.000.000.00780
Free-291.4533.2034.5733.41816
Free-487.8340.3541.9640.73800
Free-885.9646.1946.6046.33785
Free-1083.9445.7945.8645.94785
Madry 7-PGD (public model)87.2545.2946.5245.535418
CIFAR-100 WRN 32-10 (L-inf epsilon=8):
ModelNaturalPGD-20PGD-100train-time (min)
Natrual78.840.000.00811
Free-269.2015.3714.86816
Free-465.2820.6420.15767
Free-862.1325.8825.58780
Free-1059.2725.1524.88776
Madry 2-PGD trained67.9417.0816.502053
Madry 7-PGD trained59.8722.7622.525157

Demo

To train a new robust model for free! run the following command specifying the replay parameter m:

python free_train.py -m 8

To evaluate a robust model using PGD-20 with 2 random restarts run:

python multi_restart_pgd_attack.py --model_dir $MODEL_DIR --num_restarts 2

Note that if you have trained a CIFAR-100 model, even for evaluation, you should pass the dataset argument. For example:

python multi_restart_pgd_attack.py --model_dir $MODEL_DIR_TO_CIFAR100 --num_restarts 2 -d cifar100

Requirements

To install all the requirements plus tensorflow for multi-gpus run: (Inspired By Illarion ikhlestov )

pip install -r requirements/gpu.txt

Alternatively, to install the requirements plus tensorflow for cpu run:

pip install -r requirements/cpu.txt

To prepare the data, please see Datasets section.

If you find the paper or the code useful for your study, please consider citing the free training paper:

@article{shafahi2019adversarial,
  title={Adversarial Training for Free!},
  author={Shafahi, Ali and Najibi, Mahyar and Ghiasi, Amin and Xu, Zheng and Dickerson, John and Studer, Christoph and Davis, Larry S and Taylor, Gavin and Goldstein, Tom},
  journal={arXiv preprint arXiv:1904.12843},
  year={2019}
}