This is the repository for Pytorch Implementation of "Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization". If you have any issues regarding this repository, please contact firstname.lastname@example.org.
You can see the original paper here
- Install cuda-8.0
- Install cudnn v5.1
- Download Pytorch for python-2.7 and clone the repository.
pip install http://download.pytorch.org/whl/cu80/torch-0.1.12.post2-cp27-none-linux_x86_64.whl pip install torchvision git clone https://github.com/meliketoy/gradcam.pytorch
"Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization".
In this repo, we will be training and testing the model with a very simple, cat vs dog dataset. You can view and download the dataset yourself by clicking the link above.
Implementation on your own private data only requires modifications in the directory within the configuration files inside each modules.
STEP 1 : Data preperation
As we are fine-tuning the model, we will only be taking a small portion of the original training set.
$ cd ./1_preprocessor $ python main > Enter mode name : split # This will make a train-validation split in your 'split_dir' in config.py > Enter mode name : check # This will print out the distribution of your split. > Enter mode name : meanstd # This will print out the meanstd value of your train set.
STEP 2 : Classification
Then, in the classifier module, run the line below
STEP 3 : Detection
After you have trained your model, there will be a model saved in the checkpoint directory. The files in directory will be automatically updated in the detector module, searched by the directory name of your training set.
In the configuration of module 4, match the 'name' variable identical to the 'name' you used in your classification training data directory name.
The heatmap generation for each of the test data can be done by running,
This will generate a heatmap which will look like
Attention for cat
Attention for dog
See README-detector for further instructions.
FUTURE WORKS : Semi-supervised Object Detection
This strategy could be used as a method to perform semi-supervised detection, a detection learning when only given the classification label and not any local annotations.