Mathematical Formulation of Grad-CAM
Unlike Class Activation Mapping (CAM) which strictly required a Global Average Pooling (GAP) layer directly preceding the softmax classifier, Grad-CAM (Selvaraju et al., 2017) generalizes interpretability to any convolutional neural network architecture by leveraging gradient flows.
Let \(y^c\) be the unnormalized score (logit) for class \(c\). Let \(A^k\) represent the \(k\)-th feature map channel of the target convolutional layer, where \(A_{i,j}^k\) is the activation at spatial coordinates \((i, j)\).
The neuron importance weights \(lpha_k^c\) capture how strongly feature map \(A^k\) influences class score \(y^c\):
lpha_k^c = rac{1}{Z} \sum_{i=1}^u \sum_{j=1}^v rac{\partial y^c}{\partial A_{i,j}^k}
where \(Z = u imes v\) is the spatial area (height \( imes\) width) of the feature map. This operation computes the global average pooling of the partial derivatives with respect to activations.
The Critical Role of the Rectified Linear Unit (ReLU)
To synthesize the final localization heatmap \(L_{ ext{Grad-CAM}}^c\), we compute a weighted combination of forward activation maps and pass the result through a ReLU activation function:
L_{ ext{Grad-CAM}}^c = ext{ReLU}\left( \sum_k lpha_k^c A^k ight)