This is my B.Sc. Thesis at CAMP, TUM, under supervision of Professor Nassir Navab, Dr. Federico Tombari with Magda Paschali as my advisor. It's a package for attacking and visualizing convolutional networks with the purpose of understanding and comparing the effects of adversarial example on such networks.
- Intro
- Tools
- Code Structure
- Requirements
- References
To be updated soon.
- Instructions
In
massRun.pyrun the functionrunGBackPropfor guided backprop method, orrunVanillaBPfor Vanilla Back prop. For instance:
runGBackProp(choose_network = 'ResNet50',
isTrained = True,
training = "Normal",
structure="",
target_example = 4,
attack_type = 'LBFGS')- For more information on
choose_network,isTrained,training,structuresee this section. - For more information on
attack_typecheck the list of attacks. ` target_examplelet's you choose between 6 sample images drawn from ImageNet if you are using a pretrained Pytorch network. In case of using a custom network, this argument is redundant, because every time a random image is chosen from CIRFAR10 test set. To change this random setting, you can changeget_paramsfunction inmisc_functions.py.
- Reference
J. T. Springenberg, A. Dosovitskiy, T. Brox, and M. Riedmiller. Striving for Simplicity: The All Convolutional Net, https://arxiv.org/abs/1412.6806
K. Simonyan, A. Vedaldi, A. Zisserman. Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps, https://arxiv.org/abs/1312.6034
- Instructions
In
massRun.pyrun the functionrunsmoothGradfor smooth guided grad method. For instance:
runsmoothGrad(choose_network = 'VGG19',
isTrained = True,
training = "Normal",
target_example = 4,
attack_type = 'SalMap')- For more information on
choose_network,isTrained,training,structuresee this section. - For more information on
attack_typecheck the list of attacks. ` target_examplelet's you choose between 6 sample images drawn from ImageNet if you are using a pretrained Pytorch network. In case of using a custom network, this argument is redundant, because every time a random image is chosen from CIRFAR10 test set. To change this random setting, you can changeget_paramsfunction inmisc_functions.py.
- Reference
D. Smilkov, N. Thorat, N. Kim, F. Viégas, M. Wattenberg. SmoothGrad: removing noise by adding noise https://arxiv.org/abs/1706.03825
- Instructions
In
massRun.pyrun the functionrunGradCamfor Grad Cam method, orrunGGradCamfor Guided Grad Cam. For instance:
runGradCam(choose_network = 'ResNet50',
isTrained = True,
target_example = 4,
attack_type = 'SalMap)- For more information on
choose_network,isTrained,training,structuresee this section. - For more information on
attack_typecheck the list of attacks. ` target_examplelet's you choose between 6 sample images drawn from ImageNet if you are using a pretrained Pytorch network. In case of using a custom network, this argument is redundant, because every time a random image is chosen from CIRFAR10 test set. To change this random setting, you can changeget_paramsfunction inmisc_functions.py.
- Reference
R. R. Selvaraju, A. Das, R. Vedantam, M. Cogswell, D. Parikh, and D. Batra. Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization, https://arxiv.org/abs/1610.02391
- Instructions
In
massRun.pyrun the functionrunExplainfor Interpretable explanations method. For instance:
runExplain(choose_network='ResNet50',
isTrained=True,
target_example=5,
iters=5,
attack_type='RPGD')- For more information on
choose_network,isTrained,training,structuresee this section. - For more information on
attack_typecheck the list of attacks. ` target_examplelet's you choose between 6 sample images drawn from ImageNet if you are using a pretrained Pytorch network. In case of using a custom network, this argument is redundant, because every time a random image is chosen from CIRFAR10 test set. To change this random setting, you can changeget_paramsfunction inmisc_functions.py.iterssets the number of iterations for optimizing the Interpretable mask. For a clean output, choose a value above 100.
- Reference
R. Fong, A. Vedaldi. Interpratable Explanations of Black Boxes by Meaningful Perturbations, https://arxiv.org/abs/1704.03296
- Instructions
Note that this method is only implemented for Pytorch pretrained AlexNet or VGG19. The method is also not supported by any of the comparison functions. Use with caution!
In massRun.py run the function runInvRep for Inverted Image Representations method. For instance:
runInvRep(choose_network = 'AlexNet',
isTrained = True,
target_example = 4,
target_layer = 10,
attack_type = 'FGSM')- For more information on
choose_network,isTrained,training,structuresee this section. - For more information on
attack_typecheck the list of attacks. ` target_examplelet's you choose between 6 sample images drawn from ImageNet if you are using a pretrained Pytorch network. In case of using a custom network, this argument is redundant, because every time a random image is chosen from CIRFAR10 test set. To change this random setting, you can changeget_paramsfunction inmisc_functions.py.target_layersets the number of the layer you want to start the inverting algorithm from.
- Reference
A. Mahendran, A. Vedaldi. Understanding Deep Image Representations by Inverting Them, https://arxiv.org/abs/1412.0035
- Instructions
Note that this method is only implemented for Pytorch pretrained AlexNet or VGG19. The method is also not supported by any of the comparison functions. Use with caution! In
massRun.pyrun the functionrunDeepDreamfor Inverted Image Representations method. For instance:
runDeepDream(choose_network = 'VGG19',
isTrained = True,
target_example = 3,
attack_type = 'FGSM',
cnn_layer = 34,
filter_pos = 94,
iters = 50)- For more information on
choose_network,isTrained,training,structuresee this section. - For more information on
attack_typecheck the list of attacks. ` target_examplelet's you choose between 6 sample images drawn from ImageNet if you are using a pretrained Pytorch network. In case of using a custom network, this argument is redundant, because every time a random image is chosen from CIRFAR10 test set. To change this random setting, you can changeget_paramsfunction inmisc_functions.py.cnn_layerfilter_positers
- Reference
D. Smilkov, N. Thorat, N. Kim, F. Viégas, M. Wattenberg. SmoothGrad: removing noise by adding noise https://arxiv.org/abs/1706.03825
To be added soon.
Dmitry Ulyanov, Andrea Vedaldi, Victor Lempitsky. Deep Image Prior, https://arxiv.org/abs/1711.10925
All the attacks are implemented using FoolBox Package.
Alexey Kurakin, Ian Goodfellow, Samy Bengio, Adversarial examples in the physical world, https://arxiv.org/abs/1607.02533
Aleksander Madry, Aleksandar Makelov, Ludwig Schmidt, Dimitris Tsipras, Adrian Vladu, Towards Deep Learning Models Resistant to Adversarial Attacks, https://arxiv.org/abs/1706.06083
Nina Narodytska, Shiva Prasad Kasiviswanathan, Simple Black-Box Adversarial Perturbations for Deep Networks, https://arxiv.org/pdf/1612.06299.pdf
Wieland Brendel, Jonas Rauber, Matthias Bethge, Decision-Based Adversarial Attacks: Reliable Attacks Against Black-Box Machine Learning Models, https://arxiv.org/abs/1712.04248
Seyed-Mohsen Moosavi-Dezfooli, Alhussein Fawzi, Pascal Frossard, DeepFool: a simple and accurate method to fool deep neural networks, https://arxiv.org/abs/1511.04599
Pedro Tabacof, Eduardo Valle. Exploring the Space of Adversarial Images, https://arxiv.org/abs/1510.05328
Nicolas Papernot, Patrick McDaniel, Somesh Jha, Matt Fredrikson, Z. Berkay Celik, Ananthram Swami. The Limitations of Deep Learning in Adversarial Settings, https://arxiv.org/abs/1511.07528
The only available option is the Pytorch Model, Pretrained on ImageNet.
- Set
choose_network = 'AlexNet'. - Set
isTrained = Trueif you want to work with the pretrained PyTorch Model. You may setisTrained = Falseto run the model with random weights for sanity check.
There are 3 available training options.
-
Pytorch Model, Pretrained on ImageNet.
- Set
choose_network = 'VGG19'. - Set
isTrained = Trueif you want to work with the pretrained PyTorch Model. You may setisTrained = Falseto run the model with random weights for sanity check.
- Set
-
Normal Custom Training on CIFAR10. You should train the model by running
normalCifar.pyif the corresponding ckpt file doesn't exist in thecustomization/trainedmodelsdirectory.- Set
choose_network = 'Custom'. - Set
structure = 'VGG19'. - Set
training = 'Normal.
- Set
-
Custom Adversarial Training on CIFAR10. You should train the model by running
adversCifar.pyif the corresponding ckpt file doesn't exist in thecustomization/trainedmodelsdirectory.- Set
choose_network = 'Custom'. - Set
structure = 'VGG19'. - Set
training = 'Adversarial.
- Set
There are 3 available training options.
- Pytorch Model, Pretrained on ImageNet.
- Set
choose_network = 'ResNet50'. - Set
isTrained = Trueif you want to work with the pretrained PyTorch Model. You may setisTrained = Falseto run the model with random weights for sanity check.
- Set
- Normal Custom Training on CIFAR10.
You should train the model by running
normalCifar.pyif the corresponding ckpt file doesn't exist in thecustomization/trainedmodelsdirectory.- Set
choose_network = 'Custom'. - Set
structure = 'ResNet50'. - Set
training = 'Normal.
- Set
- Custom Adversarial Training on CIFAR10.
You should train the model by running
adversCifar.pyif the corresponding ckpt file doesn't exist in thecustomization/trainedmodelsdirectory.- Set
choose_network = 'Custom'. - Set
structure = 'ResNet50'. - Set
training = 'Adversarial.
- Set
There are 4 functions written for making the following comparisons:
- Among Attacks(
CompareAttacks): For a specific network, one can see how different attacks are visualized using the same visualization method. It is executed frommassRun.pyby entering:
compareAttacks(vizmethod = 'Explain',
choose_network = 'Custom',
image_index = 4,
training='Normal',
structure='ResNet50'):- Among Visualization Methods(
CompareVisualization): For a specific network and attack type, one can compare chosen visualization methods. Implemented similar toCompareAttacks,
compareVisualizations(attackmethod = 'Boundary',
choose_network = 'Custom',
image_index = 5,
training='Adverarial',
structure='VGG19')- Among Networks(
CompareNetworks): For a specific attack, one can see how different networks are visualized using the same visualization method. Implemented similar toCompareAttacks,
compareNetworks(attackmethod = 'PGD,
vizmethod = 'GradCam',
image_index = 3,
training='Normal') # or `Adversarial`- Among Training (
CompareTraining): For a selected attack and network, one can compare how different training methods affect the chosen visualization. Currently Normal and adversarial training are available, distillation will soon be added. In addition for sanity check, visualization with a noisy input as well as untrained network could be shown. Implemented similar toCompareAttacks,
compareTraining(attackmethod = 'SinglePixle',
vizmethod = 'VanillaBP',
structure = 'ResNet50',
image_index = 2)An extension to runGradCam which allows you to compare the following Grad Cam visualizations:
- Natural Input Image with the correct class prediction (Ground truth)
- Adversarial Input Image with the adversarial class prediction
- Adversarial Input Image with the correct class prediction (Ground truth)
- Natural Input Image with the adversarial class prediction (The wrong network prediction when fed the adversarial image)
The arguments are similar to Grad Cam and the output will look like this:
.png)
An extension to runExplain which allows you to compare the following Interpretable Explanations visualizations:
- Natural Input Image with the correct class prediction (Ground truth)
- Adversarial Input Image with the adversarial class prediction
- Natural Input Image with the adversarial class prediction (The wrong network prediction when fed the adversarial image)
The arguments are similar to Explainable Interpretations and the output will look like this:
.png)
- open
massRun.py - Choose your function amongst the following available ones:
- Single Visualization:
runGradCam,runGradCam2,runGGradCam,runsmoothGrad,runExplain,runExplain2,runVanillaBP,runInvRep,runDeepDream.
- Comparison Visualizations:
CompareTraining,CompareVisualizaion,CompareNetworks,CompareAttacks
- As explained above there is a function for each type of visualization or comparison. The common arguments between all functions are:
-
Choose Network: Currently you can either choose pretrained
ResNet50,VGG19orAlexNetorCustomnetwork. -
Training: Choose either
NormalorAdversarial. -
Structure: Having chosen 'Custom' network, choose its structure from 'ResNet50' and 'VGG19'.
-
Attack Type: Can be chosen from:
FGSM,LBFGS,PGD,RPGD,Boundary,DeepFool,SinglePixel,SalMap -
Example Index (Only for ImageNet): Choose a number from 0-6 to choose an image from
input_images. If you are using a network trained on CIFAR10 the example would be chosen randomly.
python = 3.5
torch >= 0.4.0
torchvision >= 0.1.9
numpy >= 1.13.0
opencv >= 3.1.0
foolbox >= 1.3.1.png)
.png)
.png)
.png)
.png)
.png)