jacobgil / pytorch-grad-cam

Advanced AI Explainability for computer vision. Support for CNNs, Vision Transformers, Classification, Object detection, Segmentation, Image similarity and more.
https://jacobgil.github.io/pytorch-gradcam-book
MIT License
10.16k stars 1.53k forks source link

cam.py #321

Open colorfully-ybf opened 2 years ago

colorfully-ybf commented 2 years ago

Traceback (most recent call last): File "/media/deep/Data/4_WSOD/pytorch-grad-cam/cam.py", line 133, in grayscale_cam = cam(input_tensor=input_tensor, File "/media/deep/Data/4_WSOD/pytorch-grad-cam/pytorch_grad_cam/base_cam.py", line 188, in call return self.forward(input_tensor, File "/media/deep/Data/4_WSOD/pytorch-grad-cam/pytorch_grad_cam/base_cam.py", line 74, in forward outputs = self.activations_and_grads(input_tensor) File "/media/deep/Data/4_WSOD/pytorch-grad-cam/pytorch_grad_cam/activations_and_gradients.py", line 42, in call return self.model(x) File "/home/deep/Libraries/anaconda3/envs/wsod2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(*input, *kwargs) File "/home/deep/Libraries/anaconda3/envs/wsod2/lib/python3.8/site-packages/mmcv/runner/fp16_utils.py", line 116, in new_func return old_func(args, **kwargs) TypeError: forward() missing 1 required positional argument: 'img_metas'

jacobgil commented 2 years ago

To have any chance at helping, I would need context: what kind of model are you using, does the model forward pass work on an inout tensor? or does it expect img_metas ? You might need to create a wrapper for the model so it works on an image.

colorfully-ybf commented 2 years ago

Thank you for your answer.My model requires 4 parameters.So I need to input 4 parameters in (input_tensor = torch.autograd.Variable(input_tensor, requires_grad=True))?