CAM,即class activation map,类别响应图。grad的意思是梯度。
二者都是为了可视化:特征图对于某一类别的响应情况(特征图每一个位置对于指定类别的响应值)。
CAM只是Grad-CAM的一种特例:在最后一个特征图之后使用全局平均池化和一个线性层做分类。这种特定场景下,计算最后一层的特征图上的类别相应图。这个在Grad-CAM原文中有严格的证明。虽然这说明Grad-CAM可以在任意层特征图上计算类别响应图,但作者也指出,在浅层的特征图上计算grad-cam效果并不好,可能是因为浅层特征感受野不够,语义比较简单。
具体做法:
(1)CAM. 利用线性分类器对应于某一特定类别得分的权重(K维权值向量),对最后一层特征图的K个channel做加权平均,取ReLU,min-max normalize,进而得到只有1个channel的响应图。
(2)Grad-CAM. 利用指定类别输出得分对任意指定特征图的每个channel上的各个像素点的偏导数值,通过全局平均池化计算每个channel的权重,再加权平均,取ReLU,min-max normalize。
参考文献
[1] Zhou, Bolei, et al. "Learning deep features for discriminative localization." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.
[2] Selvaraju, Ramprasaath R., et al. "Grad-cam: Visual explanations from deep networks via gradient-based localization." Proceedings of the IEEE International Conference on Computer Vision. 2017.