class_docstr: Implementation of a particular variation of the DPatch attack.
  It follows Lee & Kolter (2019) in using sign gradients with expectations over transformations.
  The particular transformations supported in this implementation are cropping, rotations by multiples of 90 degrees,
  and changes in the brightness of the image.
  
  | Paper link (original DPatch): https://arxiv.org/abs/1806.02299v4
  | Paper link (physical-world patch from Lee & Kolter): https://arxiv.org/abs/1906.11897
class_docstr_tok: ["Implementation","of","a","particular","variation","of","the","DPatch","attack",".","It","follows","Lee","&","Kolter","(","2019",")","in","using","sign","gradients","with","expectations","over","transformations",".","The","particular","transformations","supported","in","this","implementation","are","cropping",",","rotations","by","multiples","of","90","degrees",",","and","changes","in","the","brightness","of","the","image",".","|","Paper","link","(","original","DPatch",")",":","https",":","\/\/arxiv.org\/abs\/1806.02299v4","|","Paper","link","(","physical-world","patch","from","Lee","&","Kolter",")",":","https",":","\/\/arxiv.org\/abs\/1906.11897"]
docstr: Create an instance of the :class:`.RobustDPatch`.
  
  :param estimator: A trained object detector.
  :param patch_shape: The shape of the adversarial patch as a tuple of shape (height, width, nb_channels).
  :param patch_location: The location of the adversarial patch as a tuple of shape (upper left x, upper left y).
  :param crop_range: By how much the images may be cropped as a tuple of shape (height, width).
  :param brightness_range: Range for randomly adjusting the brightness of the image.
  :param rotation_weights: Sampling weights for random image rotations by (0, 90, 180, 270) degrees
                           counter-clockwise.
  :param sample_size: Number of samples to be used in expectations over transformation.
  :param learning_rate: The learning rate of the optimization.
  :param max_iter: The number of optimization steps.
  :param batch_size: The size of the training batch.
  :param targeted: Indicates whether the attack is targeted (True) or untargeted (False).
  :param summary_writer: Activate summary writer for TensorBoard.
                         Default is `False` and deactivated summary writer.
                         If `True` save runs/CURRENT_DATETIME_HOSTNAME in current directory.
                         If of type `str` save in path.
                         If of type `SummaryWriter` apply provided custom summary writer.
                         Use hierarchical folder structure to compare between runs easily. e.g. pass in
                         ‘runs/exp1’, ‘runs/exp2’, etc. for each new experiment to compare across them.
  :param verbose: Show progress bars.
docstr_tok: ["Create","an","instance","of","the",":","class",":","`",".RobustDPatch","`",".",":","param","estimator",":","A","trained","object","detector",".",":","param","patch_shape",":","The","shape","of","the","adversarial","patch","as","a","tuple","of","shape","(","height",",","width",",","nb_channels",")",".",":","param","patch_location",":","The","location","of","the","adversarial","patch","as","a","tuple","of","shape","(","upper","left","x",",","upper","left","y",")",".",":","param","crop_range",":","By","how","much","the","images","may","be","cropped","as","a","tuple","of","shape","(","height",",","width",")",".",":","param","brightness_range",":","Range","for","randomly","adjusting","the","brightness","of","the","image",".",":","param","rotation_weights",":","Sampling","weights","for","random","image","rotations","by","(","0",",","90",",","180",",","270",")","degrees","counter-clockwise",".",":","param","sample_size",":","Number","of","samples","to","be","used","in","expectations","over","transformation",".",":","param","learning_rate",":","The","learning","rate","of","the","optimization",".",":","param","max_iter",":","The","number","of","optimization","steps",".",":","param","batch_size",":","The","size","of","the","training","batch",".",":","param","targeted",":","Indicates","whether","the","attack","is","targeted","(","True",")","or","untargeted","(","False",")",".",":","param","summary_writer",":","Activate","summary","writer","for","TensorBoard",".","Default","is","`","False","`","and","deactivated","summary","writer",".","If","`","True","`","save","runs\/CURRENT_DATETIME_HOSTNAME","in","current","directory",".","If","of","type","`","str","`","save","in","path",".","If","of","type","`","SummaryWriter","`","apply","provided","custom","summary","writer",".","Use","hierarchical","folder","structure","to","compare","between","runs","easily",".","e.g",".","pass","in","\u2018","runs\/exp1","\u2019",",","\u2018","runs\/exp2","\u2019",",","etc",".","for","each","new","experiment","to","compare","across","them",".",":","param","verbose",":","Show","progress","bars","."]
code: def __init__(
      self,
      estimator: "OBJECT_DETECTOR_TYPE",
      patch_shape: Tuple[int, int, int] = (40, 40, 3),
      patch_location: Tuple[int, int] = (0, 0),
      crop_range: Tuple[int, int] = (0, 0),
      brightness_range: Tuple[float, float] = (1.0, 1.0),
      rotation_weights: Union[
          Tuple[float, float, float, float], Tuple[int, int, int, int]
      ] = (1, 0, 0, 0),
      sample_size: int = 1,
      learning_rate: float = 5.0,
      max_iter: int = 500,
      batch_size: int = 16,
      targeted: bool = False,
      summary_writer: Union[str, bool, SummaryWriter] = False,
      verbose: bool = True,
  ):
      """
      Create an instance of the :class:`.RobustDPatch`.
  
      :param estimator: A trained object detector.
      :param patch_shape: The shape of the adversarial patch as a tuple of shape (height, width, nb_channels).
      :param patch_location: The location of the adversarial patch as a tuple of shape (upper left x, upper left y).
      :param crop_range: By how much the images may be cropped as a tuple of shape (height, width).
      :param brightness_range: Range for randomly adjusting the brightness of the image.
      :param rotation_weights: Sampling weights for random image rotations by (0, 90, 180, 270) degrees
                               counter-clockwise.
      :param sample_size: Number of samples to be used in expectations over transformation.
      :param learning_rate: The learning rate of the optimization.
      :param max_iter: The number of optimization steps.
      :param batch_size: The size of the training batch.
      :param targeted: Indicates whether the attack is targeted (True) or untargeted (False).
      :param summary_writer: Activate summary writer for TensorBoard.
                             Default is `False` and deactivated summary writer.
                             If `True` save runs/CURRENT_DATETIME_HOSTNAME in current directory.
                             If of type `str` save in path.
                             If of type `SummaryWriter` apply provided custom summary writer.
                             Use hierarchical folder structure to compare between runs easily. e.g. pass in
                             ‘runs/exp1’, ‘runs/exp2’, etc. for each new experiment to compare across them.
      :param verbose: Show progress bars.
      """
  
      super().__init__(
          estimator=estimator, summary_writer=summary_writer
      )
  
      self.patch_shape = patch_shape
      self.learning_rate = learning_rate
      self.max_iter = max_iter
      self.batch_size = batch_size
      if self.estimator.clip_values is None:
          self._patch = np.zeros(
              shape=patch_shape, dtype=config.ART_NUMPY_DTYPE
          )
      else:
          self._patch = (
              np.random.randint(0, 255, size=patch_shape)
              / 255
              * (
                  self.estimator.clip_values[1]
                  - self.estimator.clip_values[0]
              )
              + self.estimator.clip_values[0]
          ).astype(config.ART_NUMPY_DTYPE)
      self.verbose = verbose
      self.patch_location = patch_location
      self.crop_range = crop_range
      self.brightness_range = brightness_range
      self.rotation_weights = rotation_weights
      self.sample_size = sample_size
      self._targeted = targeted
      self._check_params()
  
file_path: adversarial-robustness-toolbox/art/attacks/evasion/dpatch_robust.py
imports: import logging
  import math
  import random
  from typing import Dict, List, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  from tqdm.auto import trange
  from art.attacks.attack import EvasionAttack
  from art.estimators.estimator import BaseEstimator, LossGradientsMixin
  from art.estimators.object_detection.object_detector import ObjectDetectorMixin
  from art import config
  from art.summary_writer import SummaryWriter
label_desc: Use image node_id 1 to create a new RobustDPatch object from inherited base classes: EvasionAttack with example: obj = RobustDPatch(estimator, patch_shape, patch_location, crop_range, brightness_range, rotation_weights, sample_size, learning_rate, max_iter, batch_size, targeted, summary_writer, verbose)