...
/Generative Adversarial Examples: Working with Classifier
Generative Adversarial Examples: Working with Classifier
Practice generating adversarial examples and breaking some models using cats vs. dogs dataset.
We'll cover the following...
Let's try generating adversarial examples with GANs and break some models.
Preparing an ensemble classifier for Kaggle’s cats vs. dogs
⚠️ The dataset is intended only for non-commercial research and educational use.
To make our demonstration more similar to practical scenarios, we will train a decent model on Kaggle’s
For convenience, after downloading the dataset, put images of cats and dogs in separate folders so that the file structure looks like this:
/cats-dogs-kaggle/cat/cat.0.jpg/cat.1.jpg.../dog/dog.0.jpg/dog.1.jpg...
The model we are training on this dataset is formed of several pre-trained models provided by
Now, we need to load and preprocess the data, create an ensemble classifier, and train this model. Here are the detailed steps:
Create a Python file named
cats_
dogs.py
and import the Python modules:
import argparseimport osimport randomimport sysimport matplotlib.pyplot as pltimport numpy as npimport torchimport torch.nn as nnimport torch.backends.cudnn as cudnnimport torch.utils.dataimport torchvisionimport torchvision.datasets as dsetimport torchvision.utils as vutilsimport utilsfrom advGAN import AdvGAN_Attackfrom data_utils import data_prefetcher, _transforms_catsdogsfrom model_ensemble import transfer_init, ModelEnsemble