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.22k stars 1.54k forks source link

do it not support the model trained with autocaste in pytorch? #329

Open coallar opened 2 years ago

coallar commented 2 years ago

hi bro, i have a error happening 1) i train a model using autocaste. 2) i vis the result using trained model, while it coms error like this: image

how can i solve this error? the pipeline like this: self.target_layers = [self.model.model.layer4[-1]] # resnt18 self.cam = GradCAM(model=self.model, target_layers=self.target_layers, use_cuda=True)

load img

....

forward it

grayscale_cam = self.cam(input_tensor=aug_im)

jacobgil commented 2 years ago

Hi, So what is the type of img here? Is it float16?

Is there a chance you can modify the source code to do img = np.float32(img) before the resize, and check if that works ?