Interpretable Explanations of Black Boxes by Meaningful Perturbation
Ruth Fong and Andrea Vedaldi
- Install Jianming Zhang's version of Caffe, which includes implementations for the gradient, guided backprop, and excitation backprop saliency methods.
- Add models from Caffe's Model Zoo (recommended: bvlc_googlenet, vgg16, bvlc_reference_caffenet), add
force_backward: trueto each model's deploy .prototxt, and edit paths to the models in defaults.py.
- Download ImageNet images and create imdb files for train heldout and val by running the following in a python shell after
from helpers import write_imdb write_imdb($ILSVRC_DATASET/train, '../../../data/ilsvrc12/annotated_train_heldout.txt', '../../../data/ilsvrc12/annotated_train_heldout_imdb.txt') write_imdb($ILSVRC_DATASET/val, $CAFFEDIR/data/ilsvrc12/val, '../../../data/ilsvrc12/val_imdb.txt')
- Include your local copy of the above repo in your python path by running
export PYTHONPATH=$PYTHONPATH:$CAFFEDIR(or including it in your .bash_profile or .bashrc)
sh $CAFFEDIR/data/ilsvrc12/get_ilsvrc_aux.shto download ILSVRC support files.
caffe_dirto $CAFFEDIR in defaults.py.
- (Optional but quite useful) Download ImageNet Annotations: http://image-net.org/Annotation/Annotation.tar.gz (found here)
- (Optional, for animal parts experiment only) Download animal parts annotations from here
All pycaffe files are in code/caffe/python. Public support for matconvnet will come soon (see dev branch for some experimental code).
Learn Perturbation Masks
See optimize_mask.py (the functions
generate_learned_mask provide most of the functionality).
To generate masks (and debugging figures) for the the first 10 images in the heldout set, run:
python optimize_mask.py train_heldout -f $FIG_DIR -m $MASK_DIR -g [$GPU]
See figures.ipynb to reproduce all figures in the main text. Public support for reproducing all supplementary figures will come soon.
See localization.ipynb to reproduce numbers in Table 1.
To produce weak localization bounding boxes, use the heatmaps.py:
python heatmaps.py OUT_PATH/OUT_DIR DATA_DESC HEATMAP_TYPE THRESHOLD_TYPE [MASK_DIR] [GPU]
OUT_PATH/OUT_DIRis where to save the output file with bounding box information (a directory is taken as input when
MASK_DIRis where the masks for the 50k val images are saved (only include when