captum
captum copied to clipboard
Bug: error with retrieving input dim in guided_grad_cam.py?
https://github.com/pytorch/captum/blob/43acfcd320c44e8e469bf5276af9d55cf62145aa/captum/attr/_core/guided_grad_cam.py#L211
If I understand corretly, the parameter here should be: inputs[i].shape[1:], rather then inputs[i].shape[2:]
For inputs, the shape is N-C-H-W, For inputs[i], the shape is C-H-W, thus its dim (H-W) could be inputs[i].shape[1:]
As when I run with Guided GradCAM, it keeps warning: "Couldn't appropriately interpolate GradCAM attributions for some input tensors, returning empty tensor for corresponding attributions."
Hi @ybzhaoplus,
thank you for commenting on the implementation!
The current implementation should correctly index the H and W dimensions, because an input tensor is first converted into a tuple: https://github.com/pytorch/captum/blob/43acfcd320c44e8e469bf5276af9d55cf62145aa/captum/_utils/common.py#L153
Is it possible that some of the tensors you are passing have a dimensionality less than 4? Or maybe Hope this helps
Thanks for getting back.
I checked the inputs, and the dimensionality is 4.
I bypass this step by implementing guided_grad_cam by myself with guided_backprop and gradcam in captum. I use inputs.shape[2:], and it works.
Thanks for the clarification, @ybzhaoplus.
We are interested in understanding this issue further. Do you mind sharing a Colab notebook illustrating the exception and the warning you got?
Thanks!
@ybzhaoplus is this still an open issue ?
I can't get Guided GradCAM to work in Captum 0.6.0 either, although GradCAM itself works perfectly fine. I tried different input shapes (with and without batch dimension) and interpolation modes, but it always results in the following error:
UserWarning: Couldn't appropriately interpolate GradCAM attributions for some input tensors, returning empty tensor for corresponding attributions.
My network is composed of 3 conv3d+maxpool+relu+batchnorm blocks followed some linear layers.