forked from jacobgil/pytorch-grad-cam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheigen_cam.py
23 lines (19 loc) · 839 Bytes
/
eigen_cam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from pytorch_grad_cam.base_cam import BaseCAM
from pytorch_grad_cam.utils.svd_on_activations import get_2d_projection
# https://arxiv.org/abs/2008.00299
class EigenCAM(BaseCAM):
def __init__(self, model, target_layers, use_cuda=False,
reshape_transform=None):
super(EigenCAM, self).__init__(model,
target_layers,
use_cuda,
reshape_transform,
uses_gradients=False)
def get_cam_image(self,
input_tensor,
target_layer,
target_category,
activations,
grads,
eigen_smooth):
return get_2d_projection(activations)