Closed juanpabloalfonzo closed 3 years ago
Hi,
I think the issue is target_layer = model.fc
The target layer output should have spatial dimensions.
The gradient then is 1d and np.mean(grads, axis=(2,3)) fails because axis 2 and 3 (X and Y) don't exist.
Ah I see yea seems I was trying to pass it a linear layer at the end of the model rather than a convolution layer. Thanks!
Hello, when I try to run the script bellow I get an IndexError: tuple index out of range and I am not quite sure why.
`from pytorch_grad_cam import GradCAM, ScoreCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM from pytorch_grad_cam.utils.image import show_cam_on_image
trans=transforms.ToTensor()
model = model target_layer = model.fc
input_tensor =trans(resize_image(image[14][0]))
input_tensor=input_tensor.unsqueeze(0) input_tensor=input_tensor.to('cuda')
cam = GradCAM(model=model, target_layer=target_layer, use_cuda='args.use_cuda')
target_category = None
grayscale_cam = cam(input_tensor=input_tensor, target_category=target_category)
grayscale_cam = grayscale_cam[0,:] visualization = show_cam_on_image(rgb_img, grayscale_cam)`
I then get the following error traceback:
`IndexError: tuple index out of range
IndexError Traceback (most recent call last)