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

3D CNN grad-cam: failing in scale_cam_image function #506

Closed neeleshbisht99 closed 3 months ago

neeleshbisht99 commented 3 months ago

I'm trying to use pytorch_grad_cam for a 3D CNN model. But it is failing maybe because of this code:

if len(img.shape) > 3:
                img = zoom(np.float32(img), [
                           (t_s / i_s) for i_s, t_s in zip(img.shape, target_size[::-1])])
            else:
                img = cv2.resize(np.float32(img), target_size)

Shoudln't the condition be len(img.shape) >= 3 for 3d datasets ?

All the code for the model and the error trace (in the last section) can be seen here : https://nbviewer.org/gist/neeleshbisht99/8bdc320fc49c69f3b90af06c9ceab2fa

neeleshbisht99 commented 3 months ago

Also, it would be very helpful for many people if we could include a working example for 3D CNNs. It's evident from the number of issue that have opened in the past, that lots of people are facing issues while using the package for 3D CNNs.

Maybe we can add the above gist as an example for 3D CNN, in the repo itself, once we get that gist in working condition.

what say @jacobgil ?