class_docstr: A unittest class for testing Spatial attack.
class_docstr_tok: ["A","unittest","class","for","testing","Spatial","attack","."]
docstr: Third test with the PyTorchClassifier.
  :return:
docstr_tok: ["Third","test","with","the","PyTorchClassifier",".",":","return",":"]
code: def test_3_pytorch_classifier(self):
      """
      Third test with the PyTorchClassifier.
      :return:
      """
      x_train_mnist = np.reshape(
          self.x_train_mnist, (self.x_train_mnist.shape[0], 1, 28, 28)
      ).astype(np.float32)
      x_test_mnist = np.reshape(
          self.x_test_mnist, (self.x_test_mnist.shape[0], 1, 28, 28)
      ).astype(np.float32)
      x_test_original = x_test_mnist.copy()
  
      # Build PyTorchClassifier
      ptc = get_image_classifier_pt(from_logits=True)
  
      # Attack
      attack_st = SpatialTransformation(
          ptc,
          max_translation=10.0,
          num_translations=3,
          max_rotation=30.0,
          num_rotations=3,
          verbose=False,
      )
      x_train__mnistadv = attack_st.generate(x_train_mnist)
  
      self.assertAlmostEqual(
          x_train__mnistadv[0, 0, 13, 18], 0.627451, delta=0.01
      )
      self.assertAlmostEqual(attack_st.fooling_rate, 0.57, delta=0.03)
  
      self.assertEqual(attack_st.attack_trans_x, 0)
      self.assertEqual(attack_st.attack_trans_y, 3)
      self.assertEqual(attack_st.attack_rot, 0.0)
  
      x_test_adv = attack_st.generate(x_test_mnist)
  
      self.assertLessEqual(
          abs(x_test_adv[0, 0, 14, 14] - 0.008591662), 0.01
      )
  
      # Check that x_test has not been modified by attack and classifier
      self.assertAlmostEqual(
          float(np.max(np.abs(x_test_original - x_test_mnist))),
          0.0,
          delta=0.00001,
      )
  
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 4 for calling the TestSpatialTransformation obj's underlying member method code with example usage: obj.test_3_pytorch_classifier() without return types