class_docstr: To run: "python -m saliency.core.grad_cam_test" from top-level saliency directory.
class_docstr_tok: ["To","run",":","``","python","-m","saliency.core.grad_cam_test","''","from","top-level","saliency","directory","."]
docstr: Tests the GradCAM method using a simple network.
  
  Simple test case where the network contains one convolutional layer that
  acts as a horizontal line detector and the input image is a 5x5 matrix with
  a centered 3x3 grid of 1s and 0s elsewhere.
  
  The call_model_function returns the gradients without the outermost batch
  dimension, so the expectation is that a ValueError will be raised.
docstr_tok: ["Tests","the","GradCAM","method","using","a","simple","network",".","Simple","test","case","where","the","network","contains","one","convolutional","layer","that","acts","as","a","horizontal","line","detector","and","the","input","image","is","a","5x5","matrix","with","a","centered","3x3","grid","of","1s","and","0s","elsewhere",".","The","call_model_function","returns","the","gradients","without","the","outermost","batch","dimension",",","so","the","expectation","is","that","a","ValueError","will","be","raised","."]
code: def testGradCamErrorGradientsMismatch(self):
      """Tests the GradCAM method using a simple network.
  
      Simple test case where the network contains one convolutional layer that
      acts as a horizontal line detector and the input image is a 5x5 matrix with
      a centered 3x3 grid of 1s and 0s elsewhere.
  
      The call_model_function returns the gradients without the outermost batch
      dimension, so the expectation is that a ValueError will be raised.
      """
  
      def create_call_model_function():
          def call_model(
              x_value_batch, call_model_args=None, expected_keys=None
          ):
              grad = np.zeros(x_value_batch.shape)
              output = np.zeros(x_value_batch.shape)
              return {
                  CONVOLUTION_LAYER_VALUES: output,
                  CONVOLUTION_OUTPUT_GRADIENTS: grad[0],
              }
  
          return call_model
  
      call_model_function = create_call_model_function()
  
      # Generate test input (centered matrix of 1s surrounded by 0s)
      # and generate corresponding GradCAM mask
      img = np.zeros([INPUT_HEIGHT_WIDTH, INPUT_HEIGHT_WIDTH])
      img[1:-1, 1:-1] = 1
      img = img.reshape([INPUT_HEIGHT_WIDTH, INPUT_HEIGHT_WIDTH, 1])
      expected_error = SHAPE_ERROR_MESSAGE[
          CONVOLUTION_OUTPUT_GRADIENTS
      ].format("1", "5")
  
      with self.assertRaisesRegex(ValueError, expected_error):
          self.grad_cam_instance.GetMask(
              img,
              call_model_function=call_model_function,
              call_model_args=None,
              should_resize=True,
              three_dims=False,
          )
  
file_path: saliency/saliency/core/grad_cam_test.py
imports: import unittest
  import unittest.mock
  from .base import SHAPE_ERROR_MESSAGE
  from .None import grad_cam
  import numpy
label_desc: Use image node_id 4 for calling the GradCamTest obj's underlying member method code with example usage: obj.testGradCamErrorGradientsMismatch() and returns: call_model, dict