Changes for notebooks/04 - Case Study - Adversarial Detection.ipynb: 5 added lines, 138 removed lines.
Original line number
Diff line number
Diff line
%% Cell type:markdown id: tags:
### Adversarial Detection using FeatureSqueezing and MagNet
In this notebook, we'll explore adversarial detection using FeatureSqueezing and MagNet. This code has been adapted from [the EvadeML repository](https://github.com/mzweilin/EvadeML-Zoo) with changes to enable it to run properly with Python3 and Jupyter notebooks.
To run locally, I recommend following the latest instructions on the EvadeML repository and the [MagNet repository](https://github.com/Trevillie/MagNet).
Flags are {'dataset_name': <absl.flags._flag.Flag object at 0x7f5d7b1ddc18>, 'model_name': <absl.flags._flag.Flag object at 0x7f5d7b11a940>, 'select': <absl.flags._flag.BooleanFlag object at 0x7f5d7b11a9b0>, 'nb_examples': <absl.flags._flag.Flag object at 0x7f5d3c32e048>, 'balance_sampling': <absl.flags._flag.BooleanFlag object at 0x7f5d3c1f83c8>, 'test_mode': <absl.flags._flag.BooleanFlag object at 0x7f5d3c215908>, 'attacks': <absl.flags._flag.Flag object at 0x7f5d3c2159b0>, 'clip': <absl.flags._flag.Flag object at 0x7f5d3c215a58>, 'visualize': <absl.flags._flag.BooleanFlag object at 0x7f5d3c215a90>, 'robustness': <absl.flags._flag.Flag object at 0x7f5d3c215b70>, 'detection': <absl.flags._flag.Flag object at 0x7f5d3c215c18>, 'detection_train_test_mode': <absl.flags._flag.BooleanFlag object at 0x7f5d3c215c88>, 'result_folder': <absl.flags._flag.Flag object at 0x7f5d3c215d30>, 'verbose': <absl.flags._flag.BooleanFlag object at 0x7f5d3c215d68>, 'f': <absl.flags._flag.Flag object at 0x7f5d3c215e10>}
===Loading MNIST data...
Created TensorFlow session and set Keras backend.
===Defined TensorFlow model graph.
---Loaded MNIST-cleverhans model.
<class 'keras.engine.sequential.Sequential'>
Evaluating the pre-trained model...
Test accuracy on raw legitimate examples 0.9919
Mean confidence on ground truth classes 0.8897
Selected 100 examples.
Selected index in test set (sorted): 0-99:1
Test accuracy on selected legitimate examples 1.0000
Mean confidence on ground truth classes, selected 0.8992
/opt/conda/lib/python3.6/site-packages/keras/engine/saving.py:305: UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
warnings.warn('Error in loading the saved optimizer '
/opt/conda/lib/python3.6/site-packages/cleverhans/attacks/__init__.py:39: UserWarning: Argument back to attack constructors is not needed anymore and will be removed on or after 2019-03-26. All attacks are implemented using TensorFlow.
warnings.warn("Argument back to attack constructors is not needed"
===Adversarial image examples are saved in results/MNIST_100_1d1b8_cleverhans/MNIST_100_1d1b8_cleverhans_attacks_07450_examples.png
Preparing the detection dataset...
/opt/conda/lib/python3.6/site-packages/keras/engine/saving.py:305: UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.
warnings.warn('Error in loading the saved optimizer '
- How does FeatureSqueezing compare as a detection mechanism? To use the FeatureSqueezing, you will need to add proper parameters. Run the below cell for a few examples.
- Try a different attack or detection (to see all options, use `main(show_help=True)`).
- Try setting different parameters for the cleverhans attack above.
- Are your new attacks more successful? Why or why not?