Skip to content

Commit

Permalink
refactor: Renamed ISSCAM into ISCAM (#30)
Browse files Browse the repository at this point in the history
* refactor: Renamed IS-CAM now that paper is published

* refactor: Reflected changes on CAM naming

* docs: Updated documentation and README

* fix: Fixed import of ISCAM
  • Loading branch information
frgfm authored Dec 25, 2020
1 parent ecf827d commit 16e7641
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ This project is developed and maintained by the repo owner, but the implementati
- [Smooth Grad-CAM++](https://arxiv.org/abs/1908.01224): SmoothGrad mechanism coupled with GradCAM.
- [Score-CAM](https://arxiv.org/abs/1910.01279): score-weighting of class activation for better interpretability.
- [SS-CAM](https://arxiv.org/abs/2006.14255): SmoothGrad mechanism coupled with Score-CAM.
- [IS-CAM](https://arxiv.org/abs/2010.03023): integration-based variant of Score-CAM.



Expand Down
2 changes: 1 addition & 1 deletion docs/source/cams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Methods related to activation-based class activation maps.

.. autoclass:: SSCAM

.. autoclass:: ISSCAM
.. autoclass:: ISCAM


Grad-CAM
Expand Down
4 changes: 2 additions & 2 deletions scripts/cam_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from torchvision import models
from torchvision.transforms.functional import normalize, resize, to_tensor, to_pil_image

from torchcam.cams import CAM, GradCAM, GradCAMpp, SmoothGradCAMpp, ScoreCAM, SSCAM, ISSCAM
from torchcam.cams import CAM, GradCAM, GradCAMpp, SmoothGradCAMpp, ScoreCAM, SSCAM, ISCAM
from torchcam.utils import overlay_mask

VGG_CONFIG = {_vgg: dict(input_layer='features', conv_layer='features')
Expand Down Expand Up @@ -59,7 +59,7 @@ def main(args):
cam_extractors = [CAM(model, conv_layer, fc_layer), GradCAM(model, conv_layer),
GradCAMpp(model, conv_layer), SmoothGradCAMpp(model, conv_layer, input_layer),
ScoreCAM(model, conv_layer, input_layer), SSCAM(model, conv_layer, input_layer),
ISSCAM(model, conv_layer, input_layer)]
ISCAM(model, conv_layer, input_layer)]

# Don't trigger all hooks
for extractor in cam_extractors:
Expand Down
2 changes: 1 addition & 1 deletion test/test_cams.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_smooth_gradcampp(self):
self._test_extractor(extractor, model)


for cam_extractor in ['CAM', 'ScoreCAM', 'SSCAM', 'ISSCAM']:
for cam_extractor in ['CAM', 'ScoreCAM', 'SSCAM', 'ISCAM']:
def do_test(self, cam_extractor=cam_extractor):
self._test_cam(cam_extractor)
self._test_cam_arbitrary_layer(cam_extractor)
Expand Down
10 changes: 5 additions & 5 deletions torchcam/cams/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch.nn.functional as F
from typing import Optional, List

__all__ = ['CAM', 'ScoreCAM', 'SSCAM', 'ISSCAM']
__all__ = ['CAM', 'ScoreCAM', 'SSCAM', 'ISCAM']


class _CAM:
Expand Down Expand Up @@ -370,9 +370,9 @@ def __repr__(self) -> str:
return f"{self.__class__.__name__}(batch_size={self.bs}, num_samples={self.num_samples}, std={self.std})"


class ISSCAM(ScoreCAM):
"""Implements a variant of Score-CAM, based on Rakshit Naidu's `work
<https://github.com/r0cketr1kky/ISS-CAM_resources>`_.
class ISCAM(ScoreCAM):
"""Implements a class activation map extractor as described in `"IS-CAM: Integrated Score-CAM for axiomatic-based
explanations" <https://arxiv.org/pdf/2010.03023.pdf>`_.
The localization map is computed as follows:
Expand Down Expand Up @@ -402,7 +402,7 @@ class ISSCAM(ScoreCAM):
>>> from torchvision.models import resnet18
>>> from torchcam.cams import ISSCAM
>>> model = resnet18(pretrained=True).eval()
>>> cam = ISSCAM(model, 'layer4', 'conv1')
>>> cam = ISCAM(model, 'layer4', 'conv1')
>>> with torch.no_grad(): out = model(input_tensor)
>>> cam(class_idx=100)
Expand Down

0 comments on commit 16e7641

Please sign in to comment.