Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyTorch-Adversarial-PGD-Training

PyTorch implementation of Adversarial PGD Training.

Summary

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.

Requirements

pip3 install pytorchcv

Train

Run

python3 train.py

Default Settings

  • 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

Performance

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%

Test

Download

pip3 install gdown
bash setup.sh

or download data below

Run

python3 test.py

Modification

This section points out the part you may need to modify if you would like to change the dataset or the model for adversarial training.

Dataset (from data.py and train.py)

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>

Reference

About

PyTorch implementation of Adversarial PGD Training.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages