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"]
code: def _reverse_transformation(
      self,
      gradients: np.ndarray,
      patch_mask_transformed,
      transformation,
  ) -> np.ndarray:
      gradients = gradients * patch_mask_transformed
  
      # shift
      shift_h = transformation["shift_h"]
      shift_w = transformation["shift_w"]
      gradients = self._shift(gradients, -shift_h, -shift_w)
  
      # unpad
  
      pad_h_before = transformation["pad_h_before"]
      pad_w_before = transformation["pad_w_before"]
  
      if self.estimator.channels_first:
          height, width = self.patch_shape[1], self.patch_shape[2]
      else:
          height, width = self.patch_shape[0], self.patch_shape[1]
  
      if self.estimator.channels_first:
          if self.nb_dims == 3:
              gradients = gradients[
                  :,
                  pad_h_before : pad_h_before + height,
                  pad_w_before : pad_w_before + width,
              ]
          elif self.nb_dims == 4:
              gradients = gradients[
                  :,
                  :,
                  pad_h_before : pad_h_before + height,
                  pad_w_before : pad_w_before + width,
              ]
      else:
          if self.nb_dims == 3:
              gradients = gradients[
                  pad_h_before : pad_h_before + height,
                  pad_w_before : pad_w_before + width,
                  :,
              ]
          elif self.nb_dims == 4:
              gradients = gradients[
                  :,
                  pad_h_before : pad_h_before + height,
                  pad_w_before : pad_w_before + width,
                  :,
              ]
  
      # scale
      scale = transformation["scale"]
      gradients = self._scale(gradients, 1.0 / scale)
  
      # rotate
      angle = transformation["rotate"]
      gradients = self._rotate(gradients, -angle)
  
      return gradients
  
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 11 for calling the AdversarialPatchNumpy obj's underlying member method code with example usage: obj._reverse_transformation(gradients, patch_mask_transformed, transformation) and returns: gradients