pytorch-grad-cam icon indicating copy to clipboard operation
pytorch-grad-cam copied to clipboard

How to generate cams along with the predictions themselves?

Open lus105 opened this issue 2 years ago • 3 comments

In my use case, I only need to generate cams for one specific class (I am classifying hole-free and hole-present images). I am wondering if it is possible to generate cams along with actual model output? In an ideal scenario I would like to save inference time because I don't need cams for hole-free images. Thank you for your help.

lus105 avatar Feb 20 '23 06:02 lus105

Hi, were you able to get the model predictions along with the generated CAMs?

ahmed1996said avatar Mar 14 '23 05:03 ahmed1996said

The key is to modify this part https://github.com/jacobgil/pytorch-grad-cam/blob/master/pytorch_grad_cam/base_cam.py#L74 For example we could do self.outputs = outputs So then outputs could be accessed outside.

I'm traveling right now so will be able to modify this only later, but this should work.

jacobgil avatar Mar 15 '23 10:03 jacobgil

Hi @jacobgil !

I created a PR to implement this request. Please take a look at your convenience: https://github.com/jacobgil/pytorch-grad-cam/pull/419

JustasB avatar May 19 '23 16:05 JustasB