There is an excellent toolbox for adversarial attacks, defense, and benchmarks for TensorFlow called CleverHans (https://github.com/tensorflow/cleverhans). Currently, the developers are making plans to support PyTorch (https://github.com/tensorflow/cleverhans/blob/master/tutorials/future/torch/cifar10_tutorial.py). In this section, we will need to implement an adversarial example in PyTorch.
The following code snippet is based on the official tutorial by PyTorch: https://pytorch.org/tutorials/beginner/fgsm_tutorial.html. We will slightly modify the model and the creation of adversarial examples will be performed in batchs. Start with a blank file named advAttackGAN.py:
- Import the modules:
import torch ...