This repository contains a C++ implementation of the DeepFool algorithm by Moosavi-Dezfooli, Fawzi, Frossard. The implementation is based on the Caffe deep learning framework and it provides a MATLAB API.
To use the algorithm you need to:
- Install Caffe
- Download/clone the project
- Open the
import_deepfool_caffe.sh
file and set the path to your Caffe implementation at the CAFFE_PATH variable - Run:
./import_deepfool_caffe.sh
(ATTENTION: Running the script will copy the necessary files in the Caffe folder and it will also update/change the$CAFFE_PATH/matlab/+caffe/private/caffe_.cpp
file. None of the previous functionality is removed, so it should be fine.)
Then you can use the MATLAB interface, where you can:
% Define a DeepFool object:
df = caffe.DeepFool(model_file, net_file, labels_file);
% Use the object to get the perturbations of a single or more images that are in a 4-D array
% a is a 4-D MATLAB array with the images as the Caffe requires it
% (more one http://caffe.berkeleyvision.org/tutorial/interfaces.html )
perturbations = df.adversarial_perturbations(a);
% Use the object to get the perturbations, the number of iterations, the fooling label
% and the true label of the images
[pert, iter, foollab, truelab] = df.adversarial_perturbations(a);
You can also see the deepfool_example.m
as an example of how to use the tool.
The code is under development. Also it not properly cleaned and documented. Additional documentation and fixes are comming soon.