Cnncam: an open source library to produce attention heatmaps in a single line of code

Hello hello!

I’m here to share a library I built for interpretability of keras computer vision models that contain convolutional layers. It produces GradCAM heatmaps in a single function call:

from cnncam import display_heatmap

display_heatmap(model=model, # your keras model
                img=img, # your image
                predicted_class=pred, # your models prediction for the image 
                layer_name='block5_conv3', # the layer you would like to see                      
                alpha=0.6 # opacity of heatmap overlayed on image

The output represents a localization of features that were found to be important to the model’s prediction. Below is the implementation tested at various layer depths of VGG16:

The library can be downloaded through the pip command pip install cnncam. This project is still on an experimental lifecycle, so if you’d like to contribute, feel free to submit an issue/PR on I’m interested in having it work on PyTorch models as well so contribututions are greatly welcomed!

Thanks for the read!

1 Like

Very cool Rawan!
Thanks for sharing!