Class Activation Mapping is a way to enables the convolutional neural network to have remarkable localization ability despite being trained on image-level labels. I use it to visualize what my model is looking in the images.
The theory is described here: http://cnnlocalization.csail.mit.edu/
The script cam_keras.py
is the Keras implementation of Class Activation Mapping. It is based on this script in pytorch.
This project depends on latest version of
tensorflow
pillow
opencv-python
numpy
requests
Do pip install <missing_package>
to install whatever you don't have. Using conda
environment is recommended.
To get the output you have to run:
python3 cam_keras.py
Note:
- To change the model, change the
model_id
in the script. - The output image is stored in
CAM.jpg
. - To change the input image, modify the
IMG_URL
in the script.