broadwell's picture
Files from pytorch_grad_cam for legacy ResNet activations viz
d4b83d9 verified
raw
history blame contribute delete
652 Bytes
import numpy as np
from pytorch_grad_cam.base_cam import BaseCAM
class GradCAM(BaseCAM):
def __init__(self, model, target_layers, use_cuda=False,
reshape_transform=None):
super(
GradCAM,
self).__init__(
model,
target_layers,
use_cuda,
reshape_transform)
def get_cam_weights(self,
input_tensor,
target_layer,
target_category,
activations,
grads):
res = np.mean(grads, axis=(2, 3))
return res