utkuozbulak / pytorch-cnn-visualizations

Pytorch implementation of convolutional neural network visualization techniques
MIT License
7.81k stars 1.49k forks source link

GradCAM #114

Closed rashhkk closed 1 year ago

rashhkk commented 1 year ago

How to solve this kind of issue while using gradcam.py code? I am using ResNet152 architecture. Thank you.

Traceback (most recent call last): File "gradcam.py", line 112, in cam = grad_cam.generate_cam(prep_img, target_class) File "gradcam.py", line 63, in generate_cam conv_output, model_output = self.extractor.forward_pass(input_image) File "gradcam.py", line 42, in forward_pass conv_output, x = self.forward_pass_on_convolutions(x) File "gradcam.py", line 31, in forward_pass_on_convolutions x = module(x) # Forward File "C:\Users\Rashi\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "C:\Users\Rashi\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\linear.py", line 94, in forward return F.linear(input, self.weight, self.bias) File "C:\Users\Rashi\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\functional.py", line 1753, in linear return torch._C._nn.linear(input, weight, bias) RuntimeError: mat1 and mat2 shapes cannot be multiplied (2048x1 and 2048x2)

utkuozbulak commented 1 year ago

You need to modify the code to accommodate nested nature of residual layers. If I remember correctly, there are some implementations in the closed issues. You can have a look there.