Update gradcam.py
Browse files- gradcam.py +4 -3
gradcam.py
CHANGED
@@ -74,9 +74,10 @@ class GradCam():
|
|
74 |
def print_top_categories(self, model, img_tensor, top_k=5):
|
75 |
logits = model(img_tensor.unsqueeze(0)).logits
|
76 |
probabilities = torch.nn.functional.softmax(logits, dim=1)
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
80 |
|
81 |
def reshape_transform_vit_huggingface(self, x):
|
82 |
activations = x[:, 1:, :]
|
|
|
74 |
def print_top_categories(self, model, img_tensor, top_k=5):
|
75 |
logits = model(img_tensor.unsqueeze(0)).logits
|
76 |
probabilities = torch.nn.functional.softmax(logits, dim=1)
|
77 |
+
topIdx = logits.cpu()[0, :].detach().numpy().argsort()[-1]
|
78 |
+
topClass = model.config.id2label[topIdx]
|
79 |
+
topScore = probabilities[0][topIdx].item()
|
80 |
+
return {"label": topClass, "score": topScore}
|
81 |
|
82 |
def reshape_transform_vit_huggingface(self, x):
|
83 |
activations = x[:, 1:, :]
|