A customizable lightweight implementation of Grad-CAM (Gradient-weighted Class Activation Mapping) arXiv. This implementation works for custom models.
from grad_cam import grad_cam
grad_cam(<Model>, <Image>, <Layer>, <Label>)
<Model>
: A pytorch model.
<Image>
: Transformed image for caculating Grad-CAM, a three dimensional tensor.
<Layer>
: The layer to back-prop to for calculating gradients.
<Label>
: The label to start back-prop.
See example.py
for examples.
'Boxer' label and 'Tiger Cat' label for the same image:
Boxer | Tiger Cat |
---|---|
'African elephant, Loxodonta africana' label for an image containing an elephant:
African elephant, Loxodonta africana |
---|