class_docstr: Compute class activation map from the last fully-connected layers before the spatial pooling.
  This implementation is based on:
  
      Zhou et al., Learning Deep Features for Discriminative Localization. CVPR '16,
      https://arxiv.org/abs/1512.04150
  
  Examples
  
  .. code-block:: python
  
      import torch
  
      # densenet 2d
      from monai.networks.nets import DenseNet121
      from monai.visualize import CAM
  
      model_2d = DenseNet121(spatial_dims=2, in_channels=1, out_channels=3)
      cam = CAM(nn_module=model_2d, target_layers="class_layers.relu", fc_layers="class_layers.out")
      result = cam(x=torch.rand((1, 1, 48, 64)))
  
      # resnet 2d
      from monai.networks.nets import seresnet50
      from monai.visualize import CAM
  
      model_2d = seresnet50(spatial_dims=2, in_channels=3, num_classes=4)
      cam = CAM(nn_module=model_2d, target_layers="layer4", fc_layers="last_linear")
      result = cam(x=torch.rand((2, 3, 48, 64)))
  
  N.B.: To help select the target layer, it may be useful to list all layers:
  
  .. code-block:: python
  
      for name, _ in model.named_modules(): print(name)
  
  See Also:
  
      - :py:class:`monai.visualize.class_activation_maps.GradCAM`
docstr: Args:
      nn_module: the model to be visualized
      target_layers: name of the model layer to generate the feature map.
      fc_layers: a string or a callable used to get fully-connected weights to compute activation map
          from the target_layers (without pooling).  and evaluate it at every spatial location.
      upsampler: An upsampling method to upsample the output image. Default is
          N dimensional linear (bilinear, trilinear, etc.) depending on num spatial
          dimensions of input.
      postprocessing: a callable that applies on the upsampled output image.
          Default is normalizing between min=1 and max=0 (i.e., largest input will become 0 and
          smallest input will become 1).
code: def __init__(
      self,
      nn_module: nn.Module,
      target_layers: str,
      fc_layers: str | Callable = "fc",
      upsampler: Callable = default_upsampler,
      postprocessing: Callable = default_normalizer,
  ) -> None:
      """
      Args:
          nn_module: the model to be visualized
          target_layers: name of the model layer to generate the feature map.
          fc_layers: a string or a callable used to get fully-connected weights to compute activation map
              from the target_layers (without pooling).  and evaluate it at every spatial location.
          upsampler: An upsampling method to upsample the output image. Default is
              N dimensional linear (bilinear, trilinear, etc.) depending on num spatial
              dimensions of input.
          postprocessing: a callable that applies on the upsampled output image.
              Default is normalizing between min=1 and max=0 (i.e., largest input will become 0 and
              smallest input will become 1).
      """
      super().__init__(
          nn_module=nn_module,
          target_layers=target_layers,
          upsampler=upsampler,
          postprocessing=postprocessing,
          register_backward=False,
      )
      self.fc_layers = fc_layers
  
imports: from __future__ import annotations
  import warnings
  from collections.abc import Callable, Sequence
  from typing import cast
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from monai.config import NdarrayTensor
  from monai.transforms import ScaleIntensity
  from monai.utils import ensure_tuple, pytorch_after
  from monai.visualize.visualizer import default_upsampler
label_desc: Use image node_id 1 to create a new CAM object from inherited base classes: CAMBase with example: obj = CAM(nn_module, target_layers, fc_layers, upsampler, postprocessing)