Breaking the classifier with advGAN

The GAN model we'll use for generating adversarial examples is largely borrowed from Let's create two files named and and put the following code in these files:

  1. Within this file, you will see the following:
import torch.nn as nnimport torchimport numpy as npimport modelsimport torch.nn.functional as Fimport torchvisionimport osdef weights_init(m):    classname = m.__class__.__name__    if classname.find('Conv') != -1:        nn.init.normal_(, 0.0, 0.02)    elif classname.find('BatchNorm') != -1:        nn.init.normal_(, 1.0, 0.02)        nn.init.constant_(, 0)class AdvGAN_Attack:    def __init__(self,                 device,                 model, model_num_labels, ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.