-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for 3D Conv-Net #466
Conversation
Hey, sorry for the late reply. Is there a way to share an example use case for this: maybe some model and and input image example, |
pytorch_grad_cam/base_cam.py
Outdated
weights = self.get_cam_weights(input_tensor, | ||
target_layer, | ||
targets, | ||
activations, | ||
grads) | ||
weighted_activations = weights[:, :, None, None] * activations | ||
w_shape = (slice(None), slice(None)) + (None,) * (len(activations.shape)-2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is a bit less straight forward to understand.
Can you please explain what's going on here?
Do you think there is a way to rewrite it to be more clear ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That line does exactly the same thing as
# 2D conv
if len(activations.shape) == 4:
weighted_activations = weights[:, :, None, None] * activations
# 3D conv
elif len(activations.shape) == 5:
weighted_activations = weights[:, :, None, None, None] * activations
But I think you are right: it does lack some readability.
I will rewrite the code here.
@jacobgil Thanks for your reply!
I added an animation of gradcam-visualized CT scans in the readme. |
@kevinkevin556 Thanks for providing the code for applying Grad-Cam on 3D CNN! I have used your code to get the grad-cam outputs, my input 3D image tensor size is (1, 1, 24, 224, 224) representing (batch, channel, depth, height, width). Looking forward to your replying, thanks! |
@Syax19 Sorry for the late reply. I'm glad to hear that someone is using it 😄 Although I followed MONAI's convention to assign each dimension in the order of (height, width, depth), the output dimensions should still correspond with your input tensor, as there is no dimension swap when calculating Grad-CAM. Therefore, the |
@jacobgil |
This is incredible functionality, thank you so much for contributing this, and sorry for being so late with my reply. |
@kevinkevin556 merged!! better late than never. Thank you so much for this contribution! |
Hi all,
Thank you for developing such a nice repo. I've been using it in many of my projects for network explainability, and it has been incredibly convenient!
Recently, I've been working with medical datasets using 3D-UNet. However, I noticed that 3D convolution is not yet supported in this library, and there are also some issues like #351 requesting for the feature. Therefore, I made several changes on GradCAM and BaseCAM to extend the functionality of GradCAM to support 3D images.
Please let me know if you have any questions or suggestions regarding the changes I've implemented. I'm excited to contribute to this project and look forward to your feedback!