class_docstr: A unittest class for testing Spatial attack.
class_docstr_tok: ["A","unittest","class","for","testing","Spatial","attack","."]
docstr: Second test with the KerasClassifier.
  :return:
docstr_tok: ["Second","test","with","the","KerasClassifier",".",":","return",":"]
code: def test_4_keras_classifier(self):
      """
      Second test with the KerasClassifier.
      :return:
      """
      x_test_original = self.x_test_mnist.copy()
  
      # Build KerasClassifier
      krc = get_image_classifier_kr()
  
      # Attack
      attack_st = SpatialTransformation(
          krc,
          max_translation=10.0,
          num_translations=3,
          max_rotation=30.0,
          num_rotations=3,
          verbose=False,
      )
      x_train_adv = attack_st.generate(self.x_train_mnist)
  
      self.assertAlmostEqual(
          x_train_adv[0, 8, 13, 0], 0.49004024, delta=0.01
      )
      self.assertAlmostEqual(attack_st.fooling_rate, 0.71, delta=0.02)
  
      self.assertEqual(attack_st.attack_trans_x, 3)
      self.assertEqual(attack_st.attack_trans_y, 3)
      self.assertEqual(attack_st.attack_rot, 30.0)
  
      x_test_adv = attack_st.generate(self.x_test_mnist)
  
      self.assertAlmostEqual(
          x_test_adv[0, 14, 14, 0], 0.013572651, delta=0.01
      )
  
      # Check that x_test has not been modified by attack and classifier
      self.assertAlmostEqual(
          float(np.max(np.abs(x_test_original - self.x_test_mnist))),
          0.0,
          delta=0.00001,
      )
  
      k.clear_session()
  
file_path: adversarial-robustness-toolbox/tests/attacks/test_spatial_transformation.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import keras.backend
  import numpy
  from art.attacks.evasion.spatial_transformation import SpatialTransformation
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from tests.utils import TestBase
  from tests.utils import get_image_classifier_tf, get_image_classifier_kr
  from tests.utils import get_image_classifier_pt, get_tabular_classifier_kr
  from tests.attacks.utils import backend_test_classifier_type_check_fail
label_desc: Use image node_id 3 for calling the TestSpatialTransformation obj's underlying member method code with example usage: obj.test_4_keras_classifier() without return types