class_docstr: Implementation of the adversarial patch attack for square and rectangular images and videos in Numpy.
  
  | Paper link: https://arxiv.org/abs/1712.09665
class_docstr_tok: ["Implementation","of","the","adversarial","patch","attack","for","square","and","rectangular","images","and","videos","in","Numpy",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1712.09665"]
docstr: Create an instance of the :class:`.AdversarialPatchNumpy`.
  
  :param classifier: A trained classifier.
  :param target: The target label for the created patch.
  :param rotation_max: The maximum rotation applied to random patches. The value is expected to be in the
         range `[0, 180]`.
  :param scale_min: The minimum scaling applied to random patches. The value should be in the range `[0, 1]`,
         but less than `scale_max`.
  :param scale_max: The maximum scaling applied to random patches. The value should be in the range `[0, 1]`, but
         larger than `scale_min.`
  :param learning_rate: The learning rate of the optimization.
  :param max_iter: The number of optimization steps.
  :param clip_patch: The minimum and maximum values for each channel in the form
         [(float, float), (float, float), (float, float)].
  :param batch_size: The size of the training batch.
  :param targeted: Indicates whether the attack is targeted (True) or untargeted (False). Currently only targeted
         attacks are supported.
  :param verbose: Show progress bars.
docstr_tok: ["Create","an","instance","of","the",":","class",":","`",".AdversarialPatchNumpy","`",".",":","param","classifier",":","A","trained","classifier",".",":","param","target",":","The","target","label","for","the","created","patch",".",":","param","rotation_max",":","The","maximum","rotation","applied","to","random","patches",".","The","value","is","expected","to","be","in","the","range","`","[","0",",","180","]","`",".",":","param","scale_min",":","The","minimum","scaling","applied","to","random","patches",".","The","value","should","be","in","the","range","`","[","0",",","1","]","`",",","but","less","than","`","scale_max","`",".",":","param","scale_max",":","The","maximum","scaling","applied","to","random","patches",".","The","value","should","be","in","the","range","`","[","0",",","1","]","`",",","but","larger","than","`","scale_min.","`",":","param","learning_rate",":","The","learning","rate","of","the","optimization",".",":","param","max_iter",":","The","number","of","optimization","steps",".",":","param","clip_patch",":","The","minimum","and","maximum","values","for","each","channel","in","the","form","[","(","float",",","float",")",",","(","float",",","float",")",",","(","float",",","float",")","]",".",":","param","batch_size",":","The","size","of","the","training","batch",".",":","param","targeted",":","Indicates","whether","the","attack","is","targeted","(","True",")","or","untargeted","(","False",")",".","Currently","only","targeted","attacks","are","supported",".",":","param","verbose",":","Show","progress","bars","."]
code: def __init__(
      self,
      classifier: "CLASSIFIER_NEURALNETWORK_TYPE",
      target: int = 0,
      rotation_max: float = 22.5,
      scale_min: float = 0.1,
      scale_max: float = 1.0,
      learning_rate: float = 5.0,
      max_iter: int = 500,
      clip_patch: Union[list, tuple, None] = None,
      batch_size: int = 16,
      targeted: bool = True,
      verbose: bool = True,
  ) -> None:
      """
      Create an instance of the :class:`.AdversarialPatchNumpy`.
  
      :param classifier: A trained classifier.
      :param target: The target label for the created patch.
      :param rotation_max: The maximum rotation applied to random patches. The value is expected to be in the
             range `[0, 180]`.
      :param scale_min: The minimum scaling applied to random patches. The value should be in the range `[0, 1]`,
             but less than `scale_max`.
      :param scale_max: The maximum scaling applied to random patches. The value should be in the range `[0, 1]`, but
             larger than `scale_min.`
      :param learning_rate: The learning rate of the optimization.
      :param max_iter: The number of optimization steps.
      :param clip_patch: The minimum and maximum values for each channel in the form
             [(float, float), (float, float), (float, float)].
      :param batch_size: The size of the training batch.
      :param targeted: Indicates whether the attack is targeted (True) or untargeted (False). Currently only targeted
             attacks are supported.
      :param verbose: Show progress bars.
      """
      super().__init__(estimator=classifier)
  
      self.target = target
      self.rotation_max = rotation_max
      self.scale_min = scale_min
      self.scale_max = scale_max
      self.learning_rate = learning_rate
      self.max_iter = max_iter
      self.batch_size = batch_size
      self.clip_patch = clip_patch
      self.targeted = targeted
      self.verbose = verbose
      self._check_params()
  
      if len(self.estimator.input_shape) not in [3, 4]:
          raise ValueError(
              "Unexpected input_shape in estimator detected. AdversarialPatch is expecting images or videos as input."
          )
  
      self.input_shape = self.estimator.input_shape
  
      self.nb_dims = len(self.input_shape)
      if self.nb_dims == 3:
          if self.estimator.channels_first:
              self.i_c = 0
              self.i_h = 1
              self.i_w = 2
          else:
              self.i_h = 0
              self.i_w = 1
              self.i_c = 2
      elif self.nb_dims == 4:
          if self.estimator.channels_first:
              self.i_c = 1
              self.i_h = 2
              self.i_w = 3
          else:
              self.i_h = 1
              self.i_w = 2
              self.i_c = 3
  
      smallest_image_edge = np.minimum(
          self.input_shape[self.i_h], self.input_shape[self.i_w]
      )
      nb_channels = self.input_shape[self.i_c]
  
      if self.estimator.channels_first:
          self.patch_shape = (
              nb_channels,
              smallest_image_edge,
              smallest_image_edge,
          )
      else:
          self.patch_shape = (
              smallest_image_edge,
              smallest_image_edge,
              nb_channels,
          )
  
      self.patch: np.ndarray
      self.mean_value = (
          self.estimator.clip_values[1] - self.estimator.clip_values[0]
      ) / 2.0 + self.estimator.clip_values[0]
      self.reset_patch(self.mean_value)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import math
  from typing import Optional, Union, Tuple, TYPE_CHECKING
  import random
  import numpy
  from scipy.ndimage import rotate, shift, zoom
  from tqdm.auto import trange
  from art.attacks.attack import EvasionAttack
  from art.attacks.evasion.adversarial_patch.utils import insert_transformed_patch
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 1 to create a new AdversarialPatchNumpy object from inherited base classes: EvasionAttack with example: obj = AdversarialPatchNumpy(classifier, target, rotation_max, scale_min, scale_max, learning_rate, max_iter, clip_patch, batch_size, targeted, verbose)