-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathkpca_cam.py
21 lines (19 loc) · 859 Bytes
/
kpca_cam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from pytorch_grad_cam.base_cam import BaseCAM
from pytorch_grad_cam.utils.svd_on_activations import get_2d_projection_kernel
class KPCA_CAM(BaseCAM):
def __init__(self, model, target_layers,
reshape_transform=None, kernel='sigmoid', gamma=None):
super(KPCA_CAM, self).__init__(model,
target_layers,
reshape_transform,
uses_gradients=False)
self.kernel=kernel
self.gamma=gamma
def get_cam_image(self,
input_tensor,
target_layer,
target_category,
activations,
grads,
eigen_smooth):
return get_2d_projection_kernel(activations, self.kernel, self.gamma)