code: def test_shape(self, cam_class, input_data, expected_shape):
      if input_data["model"] == "densenet2d":
          model = DenseNet121(
              spatial_dims=2, in_channels=1, out_channels=3
          )
      elif input_data["model"] == "densenet2d_bin":
          model = DenseNet(
              spatial_dims=2, in_channels=1, out_channels=1
          )
      elif input_data["model"] == "densenet3d":
          model = DenseNet(
              spatial_dims=3,
              in_channels=1,
              out_channels=3,
              init_features=2,
              growth_rate=2,
              block_config=(6,),
          )
      elif input_data["model"] == "densenet3d_bin":
          model = DenseNet(
              spatial_dims=3,
              in_channels=1,
              out_channels=1,
              init_features=2,
              growth_rate=2,
              block_config=(6,),
          )
      elif input_data["model"] == "senet2d":
          model = SEResNet50(
              spatial_dims=2, in_channels=3, num_classes=4
          )
      elif input_data["model"] == "senet2d_bin":
          model = SEResNet50(
              spatial_dims=2, in_channels=3, num_classes=1
          )
      elif input_data["model"] == "senet3d":
          model = SEResNet50(
              spatial_dims=3, in_channels=3, num_classes=4
          )
      elif input_data["model"] == "senet3d_bin":
          model = SEResNet50(
              spatial_dims=3, in_channels=3, num_classes=1
          )
      elif input_data["model"] == "adjoint":
          model = DenseNetAdjoint(
              spatial_dims=2, in_channels=1, out_channels=3
          )
  
      # optionally test for adjoint info
      kwargs = (
          {"adjoint_info": 42}
          if input_data["model"] == "adjoint"
          else {}
      )
  
      device = "cuda:0" if torch.cuda.is_available() else "cpu"
      model.to(device)
      model.eval()
      cam = cam_class(
          nn_module=model, target_layers=input_data["target_layers"]
      )
      image = torch.rand(input_data["shape"], device=device)
      inferred = model(image, **kwargs).max(1)[-1].cpu()
      result = cam(x=image, layer_idx=-1, **kwargs)
      np.testing.assert_array_equal(
          cam.nn_module.class_idx.cpu(), inferred
      )
  
      fea_shape = cam.feature_map_size(
          input_data["shape"], device=device, **kwargs
      )
      self.assertTupleEqual(fea_shape, input_data["feature_shape"])
      self.assertTupleEqual(result.shape, expected_shape)
      # check result is same whether class_idx=None is used or not
      result2 = cam(x=image, layer_idx=-1, class_idx=inferred, **kwargs)
      assert_allclose(result, result2)
  
file_path: MONAI/tests/test_vis_gradcam.py
imports: from __future__ import annotations
  import unittest
  from typing import Any
  import numpy
  import torch
  from parameterized import parameterized
  from monai.networks.nets import DenseNet, DenseNet121, SEResNet50
  from monai.visualize import GradCAM, GradCAMpp
  from tests.utils import assert_allclose, skip_if_quick
label_desc: Use image node_id 1 for calling the TestGradientClassActivationMap obj's underlying member method code with example usage: obj.test_shape(cam_class, input_data, expected_shape) without return types