Install Pytorch using Local Installation Guide. Then run:
- Python 3.8
- torch >=1.7.1
pip install -r requirements.txt
jupyter notebookIf you want to work on the same datasets download them using references in Datasets Section.
For more detailed reproduction please follow the WIKI.
python train_and_test_all.py --model_version=resnet18model_version: version of the model [resnet18,efficientnet,densenet]
models/saved_models/{model_version}-{dataset}-{train_skip}.pth
For more training and testing options check out Train and Eval Models Wiki
Generate attributions for rotated images. All experiments are stored in: experiments/rotation/{dataset}/{model_version}-{train_skip}/{metohod}/...
python test_rotation.py --model_version=resnet18 --dataset=edible-plants --train_skip=100%Generate attributions for images with applied filters. All experiments are stored in: experiments/filters/{dataset}/{model_version}-{train_skip}/{metohod}/...
python test_filters.py --model_version=resnet18 --dataset=edible-plants --train_skip=100%You can also paste multiple options:
python test_rotation.py --model_version=resnet18 --dataset=edible-plants --dataset=marvel --train_skip=100% --train_skip=80% --method=gradcamThis way you're going to measure results for resnet18 base models, trained on 80% and 100% of ediable-plants and marvel datasets. Tests will be done using Integrated Gradiens and GradCAM methods. At the end you'll run 1 x 2 x 2 x 2 = 8 processes.
model_version: version of the model [resnet18,efficientnet,densenet]dataset: (optional) version of the dataset [edible-plants,food101,marvel,plant-data,stanford-dogs] ifNonethen all versions are tested (--weightsparameter is ignored)train_skip: (optional, defaultNone) version of the train dataset size [100%,80%,60%,40%,20%], ifNonethen all versions are tested (--weightsparameter is ignored)method: method to test [ig,saliency,gradcam,deconv,gradshap,gbp]
method: method to test [ig,saliency,gradcam,deconv,gradshap,gbp]weights: (optional) path to.pthfile with saved model, if none pasted then default one is used (models/saved_models/{model_version}-{dataset}-{train_skip}.pth)weights: (optional) path to.pthfile with saved model, if none pasted then default one is used (models/saved_models/{model_version}-{dataset}-{train_skip}.pth)use_infidelity: (optional) if flag is set then Infidelity measure is calculateduse_sensitivity: (optional) if flag is set then Sensitivity measure is calculatedrender_results: (optional) if flag is set then script renders images with attributions (otherwise only SSIM metric is calculated)
Calculate Infidelity and Sensitivity values for given model and dataset. Measures are calculated for every method available. All experiments are stored in: experiments/{dataset}/{model_version}-{train_skip}/{metohod}/...
python measure_model.py --model_version=resnet18 --dataset=edible-plants --train_skip=100%You can also paste multiple options:
python measure_model.py --model_version=resnet18 --dataset=edible-plants --dataset=marvel --train_skip=100% --train_skip=80% --method=gradcamThis way you're going to measure results for resnet18 base models, trained on 80% and 100% of ediable-plants and marvel datasets. Measurmenets will be done using Integrated Gradiens and GradCAM methods. At the end you'll run 1 x 2 x 2 x 2 = 8 processes.
If you want to calculate results for Integrated Gradients, make sure you have enough memory on your GPU. Test were run on GTX 1080 Ti with 11GB memory available. That's not enough to calculate metrics for IG with the same number of perturbations as for other methods.
If you don't have enough memory run experiments without ig flag:
python measure_model.py --model_version=efficientnet --method=saliency --method=gradcam --method=deconv --method=gbpmodel_version: version of the model [resnet18,efficientnet,densenet]dataset: (optional) version of the dataset [edible-plants,food101,marvel,plant-data,stanford-dogs] ifNonethen all versions are tested (--weightsparameter is ignored)train_skip: (optional, defaultNone) version of the train dataset size [100%,80%,60%,40%,20%], ifNonethen all versions are tested (--weightsparameter is ignored)method: method to test [ig,saliency,gradcam,deconv,gradshap,gbp]
method: method to test [ig,saliency,gradcam,deconv,gradshap,gbp]weights: (optional) path to.pthfile with saved model, if none pasted then default one is used (models/saved_models/{model_version}-{dataset}-{train_skip}.pth)
{Model} - Multiple metrics.ipynb- All metrics for specific model.{Model} - Score vs metrics.ipynb- Comparison of metric vs score on dataset.Metrics on default datasets.ipynb- First version of metrics achieved on full datasets (not used in publication)method_samples/Resnet18 IG NoiseTunnel.ipynb- Integrated Gradients base explanationmethod_samples/Resnet18 GradientShap.ipynb- GradientShap base explanationmethod_samples/Resnet18 Deconvolution.ipynb- Deconvolution base explanationmethod_samples/Resnet18 GBP.ipynb- Guided Backpropagation base explanationmethod_samples/Resnet18 Saliency.ipynb- Saliency base explanationdataset_eda/Stanford Dogs.ipynb- EDA Stanford Dogs datasetdataset_eda/Food 101.ipynb- EDA Food 101 datasetdataset_eda/Edible wild plants.ipynb- EDA Edible wild plants dataset
IG with Noise Tunnel
IntegratedGradients: Axiomatic Attribution for Deep Networks, Mukund Sundararajan et al. 2017NoiseTunnel: Sanity Checks for Saliency Maps, Julius Adebayo et al. 2018Saliency: Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps, K. Simonyan, et. al. 2014Deconvolution: Visualizing and Understanding Convolutional Networks, Scott Lundberg et al. 2017GradientShap: A Unified Approach to Interpreting Model Predictions, Matthew D Zeiler et al. 2014Guided Backpropagation: Striving for Simplicity: The All Convolutional Net, Jost Tobias Springenberg et al. 2015Infidelity and Sensitivity: On the (In)fidelity and Sensitivity for ExplanationsROAR: A Benchmark for Interpretability Methods in Deep Neural NetworksSAM: SAM: The Sensitivity of Attribution Methods to Hyperparameters
Extract all datasets into ./data directory.
Stanford Dogs Dataset- Stanford Dogs Dataset (change folder name intoStanford_Dogs_Dataset)
Food 101- Food 101 - Foodspotting
Edible wild plants- Edible wild plants (change folder name intoEdible_wild_plants)
Plants_Dataset- Plants_Dataset[99 classes]
Marvel Heroes- Marvel Heroes
