PyTorch implementation of Adversarial PGD Training.
This work is based on Towards Deep Learning Models Resistant to Adversarial Attacks. CIFAR-10 is used as the dataset. Adversarial PGD training starts with pretrained model from PyTorchCV. You should be able to change the code into different datasets such as ImageNet, CIFAR-10/CIFAR-100, SVHN or different models (see model list) for adversarial training.
pip3 install pytorchcvpython3 train.py- batch size = 128
- SGD optimizer with learning rate = 0.1
- wrn16 for adversarial training
- PGD
- distance measurement: L-infinity
- epsilon (maximum perturbation) = 8
- alpha (step size) = 0.8
- num_iter (number of step) = 20
train accuracy: white box PGD attack accuracy evaluated on the training set (50000 images) test accuracy: white box PGD attack accuracy evaluated on the testing set (10000 images)
best performance: epoch 7, test accuracy = 48.5%
pip3 install gdown
bash setup.shor download data below
python3 test.pyThis section points out the part you may need to modify if you would like to change the dataset or the model for adversarial training.
from torchvision.datasets import CIFAR10
cifar_10_mean = (0.491, 0.482, 0.447)
cifar_10_std = (0.202, 0.199, 0.201)
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(cifar_10_mean, cifar_10_std)
])
train_set = CIFAR10(root='./data', train=True, download=True, transform=transform)
test_set = CIFAR10(root='./data', train=False, download=True, transform=transform)Model (model list)
python3 train.py --model <model name from model list>