Adversarial attacking with PyTorch

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:

  1. Import the modules:
import torch ...

Get Hands-On Generative Adversarial Networks with PyTorch 1.x now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.