Class Activation Maps in Deep Learning
An implementation in Python with Keras
Class Activation Maps (CAM) is a powerful technique used in Computer Vision for classification tasks. It allows the scientist to inspect the image to be categorized and understand which parts/pixels of that image have contributed more to the final output of the model.
Basically, imagine we build a CNN with the goal of classifying people’s pictures into “Man” and “Woman”, then we feed it with a new picture and it returns the label “Man”. With the CAM tool, we would be able to see which parts of the picture activate the “Man” class the most. This can be very useful if we want to improve the accuracy of our model and have to understand which layers need to be modified, or whether we might want to differently pre-process the training set images.
In this article, I’m going to show you the idea behind this procedure. For this purpose, I will use a pre-trained CNN, Resnet50 (read the official paper here), using weights deriving from its training on the Imagenet dataset (you can read more about this dataset here).
The image I’m going to use for this experiment is, once again, this majestic Golden Retriever: