My Fastai Course Note (18): CNN Interpretation with CAM

ifeelfree
1 min readNov 25, 2020

This note is based on Fastbook.

  1. Class activation map (CAM)

It uses the output of the last convolutional layer (just before the average pooling layer) together with the predictions to give us a heatmap visualization of why the model made its decision. This is a useful tool for interpretation.

More precisely, at each position of our final convolutional layer, we have as many filters as in the last linear layer. We can therefore compute the dot product of those activations with the final weights to get, for each location on our feature map, the score of the feature that was used to make a decision.

What is a hook? Hooks are PyTorch’s equivalent of fastai’s callback.

Model interpretation is an area of active research, and we just scraped the surface of what is possible in this brief chapter. Class activation maps give us insight into why a model predicted a certain result by showing the areas of the images that were most responsible for a given prediction. This can help us analyze false positives and figure out what kind of data is missing in our training to avoid them.

2. Gradient CAM

CAM cannot computer a heatmap for the inter layers. A variant is called Gradient CAM, which can solve the problem.

--

--