Hadi M. Dolatabadi, Sarah Erfani, and Christopher Leckie 2022
This repository contains the official implementation of the ECCV 2022 paper
Abstract: Neural networks are vulnerable to adversarial attacks: adding well-crafted, imperceptible perturbations to their input can modify their output. Adversarial training is one of the most effective approaches in training robust models against such attacks. However, it is much slower than vanilla training of neural networks since it needs to construct adversarial examples for the entire training data at every iteration, hampering its effectiveness. Recently, Fast Adversarial Training (FAT) was proposed that can obtain robust models efficiently. However, the reasons behind its success are not fully understood, and more importantly, it can only train robust models for
To install requirements:
pip install -r requirements.txt
Path | Description |
---|---|
master | The main folder containing the repository. |
├ configs | Config files containing the settings. |
├ cords | Coreset selection modules. |
├ misc | Miscellaneous files. |
├ perceptual_advex | Perceptual adversarial training modules. |
└ scripts | Training scripts for different adversarial training objectives. |
├ robust_train_FPAT.py | Perceptual adversarial training (CIFAR-10 and ImageNet-12). |
├ robust_train_l2.py |
|
├ robust_train_linf.py |
|
└ robust_train_TRADES.py | TRADES adversarial training (CIFAR-10). |
├ run_train_FPAT.py | Runner module for perceptual adversarial training. |
├ run_train_l2.py | Runner module for |
├ run_train_linf.py | Runner module for |
└ run_train_TRADES.py | Runner module for TRADES adversarial training. |
To train a robust neural network using coreset selection, first, decide the training objective (here, we provide the code for
Command | Method Description |
---|---|
CRAIG | The plain CRAIG method. |
CRAIGPB | The batch-wise version of the CRAIG method. |
CRAIG-Warm | The CRAIG method with warm-start. |
CRAIGPB-Warm | The batch-wise version of the CRAIG method with warm-start. |
GradMatch | The plain GradMatch method. |
GradMatchPB | The batch-wise version of the GradMatch method. |
GradMatch-Warm | The GradMatch method with warm-start. |
GradMatchPB-Warm | The batch-wise version of the GradMatch method with warm-start. |
To train a model, we need to run:
python run_train_<OBJ>.py \
--dataset <DATASET> \
--cnfg_dir <CONFIG_FILE> \
--ckpt_dir <CHECKPOINT_PATH> \
--attack_type <ATTACK> \
--epsilon <ATTACK_EPS> \
--alpha <ATTACK_STEP> \
--attack_iters <ITERS> \
--lr <LEARNING_RATE> \
--epochs <NUM_EPOCHS> \
--frac <CORESET_SIZE> \
--freq <SELECTION_FREQ> \
--kappa <WARM_START_FACTOR>
where the parameters' definition is given below:
Command | Method Description |
---|---|
OBJ |
Training objective (from [FPAT, l2, linf, TRADES] ). |
DATASET |
Training dataset (currently, each objective can be run on certain datasets only). |
CONFIG_FILE |
Configuration file (a few examples are given in ./configs folder.) |
CHECKPOINT_PATH |
The save\load path for the trained model. |
ATTACK |
Attack type for coreset construction. |
ATTACK_EPS |
Maximum perturbation norm. |
ATTACK_STEP |
The step-size of attack generation steps. |
ITERS |
Total number of iterations for attack generation. |
LEARNING_RATE |
The classifier learning rate. |
NUM_EPOCHS |
Total number of epochs. |
CORESET_SIZE |
The size of the coreset ( |
SELECTION_FREQ |
Frequency of coreset selection (in epochs). |
WARM_START_FACTOR |
The warm-start factor. |
For instance, let us say we want to run batch-wise version of the GradMatch method with warm-start.
Also, assume that we want to gain a 2x training time gain. We set the coreset size (
python run_train_linf.py \
--dataset cifar10 \
--cnfg_dir configs/config_gradmatchpb-warm_cifar10_robust.py \
--ckpt_dir /GradMatch_Example/ \
--attack_type PGD \
--epsilon 8 \
--alpha 1.25 \
--attack_iters 10 \
--lr 0.01 \
--epochs 120 \
--frac 0.5 \
--freq 20 \
--kappa 0.5
To provide a ground for FAIR COMPARISON, this repository would allow adversarial training with the entire training data as well. To this end, one just needs to set the type
of the dss_strategy
in their config to Full
(e.g., see the ./configs/config_full_cifar10_robust.py
config for an example.) For instance, the previous training comman can be changed to the below one in this case:
python run_train_linf.py \
--dataset cifar10 \
--cnfg_dir configs/config_full_cifar10_robust.py \
--ckpt_dir /GradMatch_Example/ \
--attack_type PGD \
--epsilon 8 \
--alpha 1.25 \
--attack_iters 10 \
--lr 0.01 \
--epochs 120 \
--frac 0.5 \
--freq 20 \
--kappa 0.5
The primary results of this work are given in the table below. Note that the running time heavily depends on the GPU device and the exact versions of each software. Hence, we recommend consistently running the code from scratch to compare training efficiency.
Table: Clean (ACC) and robust (RACC) accuracy, and total training time (T) of different adversarial training methods. All the hyper-parameters were kept the same as full training for each objective. In each case, we evaluate the robust accuracy using an attack with similar attributes as the training objective. More detail can be found in the paper. The results are averaged over 5 runs.
Objective | Data | Training | Performance Measures | ||
---|---|---|---|---|---|
ACC (%) | RACC (%) | T (mins) | |||
TRADES | CIFAR-10 | Adv. CRAIG (Ours) | 83.03 | 41.45 | 179.20 |
Adv. GradMatch (Ours) | 83.07 | 41.52 | 178.73 | ||
Full Adv. Training | 85.41 | 44.19 | 344.29 | ||
|
CIFAR-10 | Adv. CRAIG (Ours) | 80.37 | 45.07 | 148.01 |
Adv. GradMatch (Ours) | 80.67 | 45.23 | 148.03 | ||
Full Adv. Training | 83.14 | 41.39 | 292.87 | ||
|
SVHN | Adv. CRAIG (Ours) | 95.42 | 49.68 | 130.04 |
Adv. GradMatch (Ours) | 95.57 | 50.41 | 125.53 | ||
Full Adv. Training | 95.32 | 53.02 | 389.46 |
This repository is mainly built upon an older version of CORDS, COResets and Data Subset selection and Perceptual Adversarial Robustness. We thank the authors of these two repositories.
If you have found our code or paper beneficial to your research, please consider citing them as:
@inproceedings{dolatabadi2022unleashing,
title={$\ell_\infty$-Robustness and Beyond: Unleashing Efficient Adversarial Training},
author={Hadi Mohaghegh Dolatabadi and Sarah Erfani and Christopher Leckie},
booktitle = {Proceedings of the European Conference on Computer Vision ({ECCV})},
year={2022}
}
@article{dolatabadi2022adversarial,
title={Adversarial coreset selection for efficient robust training},
author={Hadi Mohaghegh Dolatabadi and Sarah Erfani and Christopher Leckie},
journal={International Journal of Computer Vision (IJCV)},
year={2023}
}