class_docstr: A unittest class for testing Adversarial Patch attack.
class_docstr_tok: ["A","unittest","class","for","testing","Adversarial","Patch","attack","."]
docstr: Third test with the PyTorchClassifier.
  :return:
docstr_tok: ["Third","test","with","the","PyTorchClassifier",".",":","return",":"]
code: def test_4_pytorch(self):
      """
      Third test with the PyTorchClassifier.
      :return:
      """
      ptc = get_image_classifier_pt(from_logits=True)
  
      x_train = np.reshape(
          self.x_train_mnist, (self.n_train, 1, 28, 28)
      ).astype(np.float32)
  
      attack_ap = AdversarialPatch(
          ptc,
          rotation_max=0.5,
          scale_min=0.4,
          scale_max=0.41,
          learning_rate=5.0,
          batch_size=10,
          max_iter=5,
          patch_shape=(1, 28, 28),
          verbose=False,
      )
  
      target = np.zeros(self.x_train_mnist.shape[0])
      patch_adv, _ = attack_ap.generate(x_train, target)
  
      self.assertAlmostEqual(patch_adv[0, 8, 8], 0.5, delta=0.05)
      self.assertAlmostEqual(patch_adv[0, 14, 14], 0.5, delta=0.05)
      self.assertAlmostEqual(
          float(np.sum(patch_adv)), 367.6218066346819, delta=4.0
      )
  
      mask = np.ones((1, 28, 28)).astype(bool)
      attack_ap.apply_patch(x=x_train, scale=0.1, mask=mask)
      attack_ap.reset_patch(initial_patch_value=None)
      attack_ap.reset_patch(initial_patch_value=1.0)
      attack_ap.reset_patch(initial_patch_value=patch_adv)
      with self.assertRaises(ValueError):
          attack_ap.reset_patch(initial_patch_value=np.array([1, 2, 3]))
  
      # Numpy
      attack_ap = AdversarialPatchNumpy(
          ptc,
          rotation_max=0.5,
          scale_min=0.4,
          scale_max=0.41,
          learning_rate=5.0,
          batch_size=10,
          max_iter=5,
          verbose=False,
      )
  
      target = np.zeros(self.x_train_mnist.shape[0])
      patch_adv, _ = attack_ap.generate(x_train, target)
  
      self.assertAlmostEqual(patch_adv[0, 8, 8], 0.6715167, delta=0.05)
      self.assertAlmostEqual(
          patch_adv[0, 14, 14], 0.6292826, delta=0.05
      )
      self.assertAlmostEqual(
          float(np.sum(patch_adv)), 424.31439208984375, delta=4.0
      )
  
      mask = np.ones((1, 28, 28)).astype(bool)
      attack_ap.apply_patch(x=x_train, scale=0.1, mask=mask)
      attack_ap.reset_patch(initial_patch_value=None)
      attack_ap.reset_patch(initial_patch_value=1.0)
      attack_ap.reset_patch(initial_patch_value=patch_adv)
      with self.assertRaises(ValueError):
          attack_ap.reset_patch(initial_patch_value=np.array([1, 2, 3]))
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import unittest
  import numpy
  import keras
  import tensorflow
  from art.attacks.evasion.adversarial_patch.adversarial_patch import AdversarialPatch, AdversarialPatchNumpy, AdversarialPatchPyTorch
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from tests.utils import TestBase, master_seed
  from tests.utils import get_image_classifier_tf, get_image_classifier_kr
  from tests.utils import get_tabular_classifier_kr, get_image_classifier_pt
  from tests.attacks.utils import backend_test_classifier_type_check_fail
label_desc: Use image node_id 6 for calling the TestAdversarialPatch obj's underlying member method code with example usage: obj.test_4_pytorch() without return types