code: def test_class_gradient(
      art_warning,
      framework,
      image_dl_estimator,
      get_default_mnist_subset,
      mnist_shape,
      store_expected_values,
      expected_values,
  ):
      try:
          (_, _), (
              x_test_mnist,
              y_test_mnist,
          ) = get_default_mnist_subset
  
          classifier, _ = image_dl_estimator(from_logits=True)
  
          (
              grad_1_all_labels,
              grad_2_all_labels,
              grad_1_label5,
              grad_2_label5,
              grad_1_labelArray,
              grad_2_labelArray,
              labels_list,
          ) = expected_values()
  
          labels = np.array(labels_list, dtype=object)
  
          # TODO we should consider checking channel independent columns to make this test truly framework independent
          def get_gradient1_column(gradients):
              if mnist_shape[0] == 1:
                  return gradients[
                      0, 5, 0, 14, :
                  ]  # expected_gradients_1_all_labels
              else:
                  return gradients[0, 5, 14, :, 0]
  
          def get_gradient2_column(gradients):
              if mnist_shape[0] == 1:
                  return gradients[
                      0, 5, 0, :, 14
                  ]  # expected_gradients_2_all_labels
              else:
                  return gradients[0, 5, :, 14, 0]
  
          def get_gradient3_column(gradients):
              if mnist_shape[0] == 1:
                  return gradients[
                      0, 0, 0, 14, :
                  ]  # expected_gradients_1_label5
              else:
                  return gradients[0, 0, 14, :, 0]
  
          def get_gradient4_column(gradients):
              if mnist_shape[0] == 1:
                  return gradients[
                      0, 0, 0, :, 14
                  ]  # expected_gradients_2_all_labels
              else:
                  return gradients[0, 0, :, 14, 0]
  
          # Test all gradients label
          gradients = classifier.class_gradient(x_test_mnist)
  
          new_shape = (
              x_test_mnist.shape[0],
              10,
          ) + mnist_shape
          assert gradients.shape == new_shape
  
          sub_gradients2 = get_gradient2_column(gradients)
          if framework != "mxnet":
              np.testing.assert_array_almost_equal(
                  sub_gradients2,
                  grad_2_all_labels[0],
                  decimal=4,
              )
  
          # Test 1 gradient label = 5
          gradients = classifier.class_gradient(x_test_mnist, label=5)
  
          assert (
              gradients.shape
              == (
                  x_test_mnist.shape[0],
                  1,
              )
              + mnist_shape
          )
  
          sub_gradients2 = get_gradient3_column(gradients)
          if framework != "mxnet":
              np.testing.assert_array_almost_equal(
                  sub_gradients2,
                  grad_1_label5[0],
                  decimal=4,
              )
  
          sub_gradients4 = get_gradient4_column(gradients)
          if framework != "mxnet":
              np.testing.assert_array_almost_equal(
                  sub_gradients4,
                  grad_2_label5[0],
                  decimal=4,
              )
  
          # # Test a set of gradients label = array
          gradients = classifier.class_gradient(
              x_test_mnist, label=labels
          )
  
          new_shape = (
              x_test_mnist.shape[0],
              1,
          ) + mnist_shape
          assert gradients.shape == new_shape
  
          sub_gradients5 = get_gradient3_column(gradients)
          if framework != "mxnet":
              np.testing.assert_array_almost_equal(
                  sub_gradients5,
                  grad_1_labelArray[0],
                  decimal=4,
              )
  
          sub_gradients6 = get_gradient4_column(gradients)
          if framework != "mxnet":
              np.testing.assert_array_almost_equal(
                  sub_gradients6,
                  grad_2_labelArray[0],
                  decimal=4,
              )
  
      except ARTTestException as e:
          art_warning(e)
  
imports: import logging
  import os
  from os import listdir, path
  import pickle
  import tempfile
  import keras
  import numpy
  import pytest
  from tensorflow.keras.callbacks import LearningRateScheduler
  from art.defences.preprocessor import FeatureSqueezing, JpegCompression, SpatialSmoothing
  from tests.utils import ARTTestException
label_desc: Use image node_id 18 for calling a global function with example usage: test_class_gradient(art_warning, framework, image_dl_estimator, get_default_mnist_subset, mnist_shape, store_expected_values, expected_values) and returns: gradients, gradients, gradients, gradients, gradients, gradients, gradients, gradients