yizt / Grad-CAM.pytorch

pytorch实现Grad-CAM和Grad-CAM++,可以可视化任意分类网络的Class Activation Map (CAM)图,包括自定义的网络;同时也实现了目标检测faster r-cnn和retinanet两个网络的CAM图;欢迎试用、关注并反馈问题...
Apache License 2.0
715 stars 166 forks source link

GradCAM.py 中module.register_backward_hook 无输出 #15

Open julyxia1992 opened 4 years ago

julyxia1992 commented 4 years ago

我在加载自己的模型后,调用 _get_grads_hook(self, module, input_grad, output_grad): 却没有输出?

yizt commented 4 years ago

@julyxia1992 您好,请问是怎么确定_get_grads_hook没有输出的?_get_grads_hook无需显示调用,loss反向传播会自动调用

julyxia1992 commented 4 years ago

非常感谢作者的代码!本人终于可以实现自己模型的目标检测的热力图

DamonAtSjtu commented 4 years ago

When I load my own model ,I also met this question, my model cannot call _get_grads_hook function automatically, how do you solve this question, thanks.

julyxia1992 commented 4 years ago

When I load my own model ,I also met this question, my model cannot call _get_grads_hook function automatically, how do you solve this question, thanks.

image = torch.as_tensor(image.astype("float32").transpose(2, 0, 1)).requires_grad_(True)

this line is in demo_retinanet.py lines140 if you did not add requiresgrad(True),it cannot call _get_grads_hook function

Fly-dream12 commented 3 years ago

I have made the requiresgrad as True, but i still can not get the gradient. Can you give some suggestions? @julyxia1992