pytorch-grad-cam
pytorch-grad-cam copied to clipboard
Gradients and activations shape in the VIT example code
I tried to run the vit example code, however, I noticed the following errors.
Python 3.9.18 (main, Sep 11 2023, 13:41:44)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytorch_grad_cam import GradCAM
>>> import torch
>>> model = torch.hub.load('facebookresearch/deit:main',
... 'deit_tiny_patch16_224', pretrained=True)
Using cache found in /home/.cache/torch/hub/facebookresearch_deit_main
>>> target_layers = [model.blocks[-1].norm1]
>>> image = torch.rand(1,3,224,224)
>>> cam = GradCAM(model=model, target_layers=target_layers)
>>> grayscale_cam = cam(input_tensor=image, targets=None)
(1, 197, 192)
Traceback (most recent call last):
File "
If I comment out the error throwing logic in grad_cam.py, then the shape check in https://github.com/jacobgil/pytorch-grad-cam/blob/1ff3f58818baa2889f3f51d0b9759783b4333ba0/pytorch_grad_cam/base_cam.py#L74 also fails.
Does the shape really matter? Is there a way to fix this or just work around it? Thanks!
pytorch '2.1.0+cu121', grad-cam 1.5.2, ubuntu 18.04