Code for "Learning defense transformations for counterattacking adversarial examples"
Python 3.7.5
Pytorch 1.5.0
cifar2png 0.0.4
torchattacks 1.3
We conduct experiments on CIFAR-10 and CIFAR-100 datasets.
For convenience, we convert CIFAR-10 and CIFAR-100 datasets into PNG images by [cifar2png].
-
Step1: assign the path of cifar10 and convert CIFAR-10 datasets into PNG images.
- run
cifar2png cifar10 datasets/cifar10
- run
-
Step2: train classifier h in Algorithm 1.
- run
python train_classifier.py --arch=resnet56
- run
-
Step3: generate a set of adversarial examples A in Algorithm 1.
- run
python data_preprocess.py
- run
-
Step4: train the defense transformer T in Algorithm 1.
- run
python main.py
- run
-
Step1: test the defense transformer over ResNet-56 on CIFAR-10.
- run
python evaluation.py --model_h_path 'pytorch_resnet_cifar10/best_model.th' --model_ST_path 'checkpoint_defense_transformer/resnet56_cifar10.pth'
- run
-
Step2: test the defense transformer over other models on other datasets.
- modify the model and dataset, train the model follow 4 steps above, and run
python evaluation.py <model_h_path> <model_ST_path> <dataroot>
- modify the model and dataset, train the model follow 4 steps above, and run