Skip to content
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

Confused about the CAM method? #7

Open
jokingww opened this issue Aug 23, 2023 · 1 comment
Open

Confused about the CAM method? #7

jokingww opened this issue Aug 23, 2023 · 1 comment

Comments

@jokingww
Copy link

Nice Work. In the code you get the cam_map using only one Conv2d layer. According to my intuition, here should not use a method like GradCAM to get CAM. And I also see this process in other place. Can you explain why this this works? Thank you.

@rajeevyasarla
Copy link
Owner

rajeevyasarla commented Jan 7, 2025

in this code I am computing CAM using https://github.com/zhoubolei/CAM

for high quality CAM map you can use GradCAM method, https://github.com/jacobgil/pytorch-grad-cam

the following code will produce CAM ma using GradCAM method

from pytorch_grad_cam import GradCAM, HiResCAM, ScoreCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM, FullGrad
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
from pytorch_grad_cam.utils.image import show_cam_on_image
from torchvision.models import resnet50

d0, d1, d2, d3, d4, d5, d6,  pred_edges, cam_map, bag_map, pred_class = dino.student_encoder(inputs_v)
target_layers = [ dino.student_encoder.class_input]
input_tensor = inputs_v
targets = [ pred_class]

with GradCAM(model= dino.student_encoder, target_layers=target_layers) as cam:
  grayscale_cam = cam(input_tensor=input_tensor, targets=targets)
  grayscale_cam = grayscale_cam[0, :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants