Using Class Activation Maps (CAM) for visualization

I wrote a small notebook on how to go about visualizing CAM here https://github.com/TheShadow29/FAI-notes/blob/master/notebooks/Using-CAM-for-CNN-Visualization.ipynb

It also covers when you have a hidden layer after the Adaptive Concat Pooling. Grad-CAM work is still in progress.

Cheers!

10 Likes

Thank you @TheShadow29 I use your code to do the same things with ResNext50 : https://github.com/trancept/deep_learning_tests/blob/master/015-HeatMap.ipynb

2 Likes

Nice. I will add a link to this in my repo as well :slight_smile:

Hi @Benoit_c / @TheShadow29 ,

I have one query regarding class activation maps. If i have a trained model which was initialized using convlearner.pretrained. Now i can load the saved model replace the last layers as per cam and then train the last layers. Is this okay ? or the idea is to retrain the whole network with modified last layers? looking forward to your response.

-bumblebee

I am not sure unfortunately. I think you can use grad-cam https://arxiv.org/pdf/1610.02391.pdf instead of replacing the last layers.

ok. cool. Thanks for prompt response. So need to do a small poc on that part. @Benoit_c any thoughts on this?

Apart from that have you been able to do a small poc on Grand Cam ?

Hi, sorry, I have to retrained the whole model. It will be better if we could visualize an existing model…

@TheShadow29, thanks a lot for sharing the code. I was trying to visualize CAM for a WideResNet model but was facing some issues in the same. Unlike Resnet, the dimensions of the fully connected layer and the last convolutional layer don’t match in the Wideresnet_50 model and hence, taking a matrix product is impossible.

Any idea on how do we go about visualizing CAM for a Wideresnet_50 model? Is it even possible?