class_docstr: Implementation of the adversarial texture attack on object trackers in PyTorch.
  
  | Paper link: https://arxiv.org/abs/1904.11042
class_docstr_tok: ["Implementation","of","the","adversarial","texture","attack","on","object","trackers","in","PyTorch",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1904.11042"]
docstr: Generate an adversarial patch and return the patch and its mask in arrays.
  
  :param x: Input videos of shape NFHWC.
  :param y: True labels of format `List[Dict[str, np.ndarray]]`, one dictionary for each input image. The keys of
            the dictionary are:
  
            - boxes [N_FRAMES, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
                                   0 <= y1 < y2 <= H.
  
  :Keyword Arguments:
      * *shuffle* (``np.ndarray``) --
        Shuffle order of samples, labels, initial boxes, and foregrounds for texture generation.
      * *y_init* (``np.ndarray``) --
        Initial boxes around object to be tracked of shape (nb_samples, 4) with second dimension representing
        [x1, y1, x2, y2] with 0 <= x1 < x2 <= W and 0 <= y1 < y2 <= H.
      * *foreground* (``np.ndarray``) --
        Foreground masks of shape NFHWC of boolean values with False/0.0 representing foreground, preventing
        updates to the texture, and True/1.0 for background, allowing updates to the texture.
      * *patch_points* (``np.ndarray``) --
        Array of shape (nb_frames, 4, 2) containing four pairs of integers (height, width) corresponding to the
        four corners top-left, top-right, bottom-right, bottom-left of the transformed image in the coordinates
        of the original image.
  
  :return: An array with images patched with adversarial texture.
docstr_tok: ["Generate","an","adversarial","patch","and","return","the","patch","and","its","mask","in","arrays",".",":","param","x",":","Input","videos","of","shape","NFHWC",".",":","param","y",":","True","labels","of","format","`","List","[","Dict","[","str",",","np.ndarray","]","]","`",",","one","dictionary","for","each","input","image",".","The","keys","of","the","dictionary","are",":","-","boxes","[","N_FRAMES",",","4","]",":","the","boxes","in","[","x1",",","y1",",","x2",",","y2","]","format",",","with","0","<","=","x1","<","x2","<","=","W","and","0","<","=","y1","<","y2","<","=","H.",":","Keyword","Arguments",":","*","*","shuffle","*","(","``","np.ndarray","``",")","--","Shuffle","order","of","samples",",","labels",",","initial","boxes",",","and","foregrounds","for","texture","generation",".","*","*","y_init","*","(","``","np.ndarray","``",")","--","Initial","boxes","around","object","to","be","tracked","of","shape","(","nb_samples",",","4",")","with","second","dimension","representing","[","x1",",","y1",",","x2",",","y2","]","with","0","<","=","x1","<","x2","<","=","W","and","0","<","=","y1","<","y2","<","=","H.","*","*","foreground","*","(","``","np.ndarray","``",")","--","Foreground","masks","of","shape","NFHWC","of","boolean","values","with","False\/0.0","representing","foreground",",","preventing","updates","to","the","texture",",","and","True\/1.0","for","background",",","allowing","updates","to","the","texture",".","*","*","patch_points","*","(","``","np.ndarray","``",")","--","Array","of","shape","(","nb_frames",",","4",",","2",")","containing","four","pairs","of","integers","(","height",",","width",")","corresponding","to","the","four","corners","top-left",",","top-right",",","bottom-right",",","bottom-left","of","the","transformed","image","in","the","coordinates","of","the","original","image",".",":","return",":","An","array","with","images","patched","with","adversarial","texture","."]
code: def generate(  # type: ignore  # pylint: disable=W0222
      self, x: np.ndarray, y: List[Dict[str, np.ndarray]], **kwargs
  ) -> np.ndarray:
      """
      Generate an adversarial patch and return the patch and its mask in arrays.
  
      :param x: Input videos of shape NFHWC.
      :param y: True labels of format `List[Dict[str, np.ndarray]]`, one dictionary for each input image. The keys of
                the dictionary are:
  
                - boxes [N_FRAMES, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
                                       0 <= y1 < y2 <= H.
  
      :Keyword Arguments:
          * *shuffle* (``np.ndarray``) --
            Shuffle order of samples, labels, initial boxes, and foregrounds for texture generation.
          * *y_init* (``np.ndarray``) --
            Initial boxes around object to be tracked of shape (nb_samples, 4) with second dimension representing
            [x1, y1, x2, y2] with 0 <= x1 < x2 <= W and 0 <= y1 < y2 <= H.
          * *foreground* (``np.ndarray``) --
            Foreground masks of shape NFHWC of boolean values with False/0.0 representing foreground, preventing
            updates to the texture, and True/1.0 for background, allowing updates to the texture.
          * *patch_points* (``np.ndarray``) --
            Array of shape (nb_frames, 4, 2) containing four pairs of integers (height, width) corresponding to the
            four corners top-left, top-right, bottom-right, bottom-left of the transformed image in the coordinates
            of the original image.
  
      :return: An array with images patched with adversarial texture.
      """
      import torch
  
      shuffle = kwargs.get("shuffle", True)
      y_init = kwargs.get("y_init")
      foreground = kwargs.get("foreground")
      if foreground is None:
          foreground = np.ones_like(x)
      patch_points = kwargs.get("patch_points")
  
      class TrackingDataset(torch.utils.data.Dataset):
          """
          Object tracking dataset in PyTorch.
          """
  
          def __init__(self, x, y, y_init, foreground):
              self.x = x
              self.y = y
              self.y_init = y_init
              self.foreground = foreground
  
          def __len__(self):
              return self.x.shape[0]
  
          def __getitem__(self, idx):
              img = self.x[idx]
  
              target = {}
              target["boxes"] = torch.from_numpy(y[idx]["boxes"])
  
              y_init_i = self.y_init[idx]
              foreground_i = self.foreground[idx]
  
              return img, target, y_init_i, foreground_i
  
      dataset = TrackingDataset(x, y, y_init, foreground)
      data_loader = torch.utils.data.DataLoader(
          dataset=dataset,
          batch_size=self.batch_size,
          shuffle=shuffle,
          drop_last=False,
      )
  
      for i_max_iter in trange(
          self.max_iter,
          desc="Adversarial Texture PyTorch",
          disable=not self.verbose,
      ):
          self._i_max_iter = i_max_iter
          self._batch_id = 0
  
          for videos_i, target_i, y_init_i, foreground_i in data_loader:
              self._batch_id += 1
              videos_i = videos_i.to(self.estimator.device)
              y_init_i = y_init_i.to(self.estimator.device)
              foreground_i = foreground_i.to(self.estimator.device)
              target_i_list = []
              for i_t in range(videos_i.shape[0]):
                  target_i_list.append(
                      {
                          "boxes": target_i["boxes"][i_t].to(
                              self.estimator.device
                          )
                      }
                  )
  
              _ = self._train_step(
                  videos=videos_i,
                  target=target_i_list,
                  y_init=y_init_i,
                  foreground=foreground_i,
                  patch_points=patch_points,
              )
  
              # Write summary
              if self.summary_writer is not None:  # pragma: no cover
                  self.summary_writer.update(
                      batch_id=self._batch_id,
                      global_step=self._i_max_iter,
                      grad=None,
                      patch=self._patch.detach().cpu().numpy(),
                      estimator=self.estimator,
                      x=videos_i.detach().cpu().numpy(),
                      y=target_i_list,
                  )
  
      if self.summary_writer is not None:
          self.summary_writer.reset()
  
      return self.apply_patch(
          x=x, foreground=foreground, patch_points=patch_points
      )
  
imports: import logging
  from typing import Dict, List, Optional, 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_tracking.object_tracker import ObjectTrackerMixin
  from art.summary_writer import SummaryWriter
label_desc: Use image node_id 7 for calling the AdversarialTexturePyTorch obj's underlying member method code with example usage: obj.generate(x, y) and returns: self, self, img,  target,  y_init_i,  foreground_i