code: def test_loss_gradient_check(self):
      (x_train, y_train), (x_test, y_test), _, _ = load_mnist()
      x_train, y_train = x_train[:NB_TRAIN], y_train[:NB_TRAIN]
      x_test, y_test = x_test[:NB_TEST], y_test[:NB_TEST]
  
      # Get classifier and train like normal
      classifier = get_image_classifier_kr()
      classifier.fit(
          x_train, y_train, batch_size=BATCH_SIZE, nb_epochs=2
      )
  
      # Now check that the function detects bad gradients
      # Set the weights of the convolution layer to zero
      weights = classifier._model.layers[0].get_weights()
      new_weights = [np.zeros(w.shape) for w in weights]
      classifier._model.layers[0].set_weights(new_weights)
      is_bad = loss_gradient_check(
          classifier, x_test, y_test, verbose=False
      )
  
      self.assertTrue(np.all(np.any(is_bad, 1)))
  
      # Set the weights of the convolution layer to nan
      weights = classifier._model.layers[0].get_weights()
      new_weights = [np.empty(w.shape) for w in weights]
      for i in range(len(new_weights)):
          new_weights[i][:] = np.nan
      classifier._model.layers[0].set_weights(new_weights)
      is_bad = loss_gradient_check(
          classifier, x_test, y_test, verbose=False
      )
  
      self.assertTrue(np.all(np.any(is_bad, 1)))
  
file_path: adversarial-robustness-toolbox/tests/metrics/test_gradient_check.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  from art.metrics.gradient_check import loss_gradient_check
  from art.utils import load_mnist
  from tests.utils import TestBase, master_seed, get_image_classifier_kr
label_desc: Use image node_id 2 for calling the TestGradientCheck obj's underlying member method code with example usage: obj.test_loss_gradient_check() without return types