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

[Feature Request] Counter Factual GCAM

Open MoH-assan opened this issue 8 months ago • 0 comments

Hi, It would be nice to support counterfactual grad-cams from section 3.3 in the original paper. https://arxiv.org/pdf/1610.02391

I guess it is a matter of changing this https://github.com/jacobgil/pytorch-grad-cam/blob/1ff3f58818baa2889f3f51d0b9759783b4333ba0/pytorch_grad_cam/base_cam.py#L141-L142 to this

            cam = self.get_cam_image(input_tensor, target_layer, targets, layer_activations, layer_grads, eigen_smooth)
            if counter_factual: #bkr
                cam = cam * -1

and passing counter_factual through call all the way to compute_cam_per_layer

I can do a pull request, but I am not very familiar with the entire code base.

Thanks,

MoH-assan avatar Jun 27 '24 11:06 MoH-assan