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: Apply a training step to the batch based on a mini-batch.
  
  :param videos: Video samples.
  :param target: Target labels/boxes.
  :param y_init: Initial labels/boxes.
  :param foreground: Foreground mask.
  :param patch_points: Array of shape (nb_frames, 4, 2) containing four pairs of integers (height, width)
                       corresponding to the coordinates of the four corners top-left, top-right, bottom-right,
                       bottom-left of the transformed image in the coordinate-system of the original image.
  :return: Loss.
docstr_tok: ["Apply","a","training","step","to","the","batch","based","on","a","mini-batch",".",":","param","videos",":","Video","samples",".",":","param","target",":","Target","labels\/boxes",".",":","param","y_init",":","Initial","labels\/boxes",".",":","param","foreground",":","Foreground","mask",".",":","param","patch_points",":","Array","of","shape","(","nb_frames",",","4",",","2",")","containing","four","pairs","of","integers","(","height",",","width",")","corresponding","to","the","coordinates","of","the","four","corners","top-left",",","top-right",",","bottom-right",",","bottom-left","of","the","transformed","image","in","the","coordinate-system","of","the","original","image",".",":","return",":","Loss","."]
code: def _train_step(
      self,
      videos: "torch.Tensor",
      target: List[Dict[str, "torch.Tensor"]],
      y_init: "torch.Tensor",
      foreground: Optional["torch.Tensor"],
      patch_points: Optional[np.ndarray],
  ) -> "torch.Tensor":
      """
      Apply a training step to the batch based on a mini-batch.
  
      :param videos: Video samples.
      :param target: Target labels/boxes.
      :param y_init: Initial labels/boxes.
      :param foreground: Foreground mask.
      :param patch_points: Array of shape (nb_frames, 4, 2) containing four pairs of integers (height, width)
                           corresponding to the coordinates of the four corners top-left, top-right, bottom-right,
                           bottom-left of the transformed image in the coordinate-system of the original image.
      :return: Loss.
      """
      import torch
  
      self.estimator.model.zero_grad()
      loss = self._loss(
          videos, target, y_init, foreground, patch_points
      )
      loss.backward(retain_graph=True)
  
      if self._patch.grad is not None:
          gradients = self._patch.grad.sign() * self.step_size
      else:
          raise ValueError("Gradient term in PyTorch model is `None`.")
  
      # 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=np.expand_dims(
                  self._patch.grad.detach().cpu().numpy(), axis=0
              ),
              patch=None,
              estimator=None,
              x=None,
              y=None,
          )
  
      self._patch.grad = torch.zeros(
          self._patch.grad.shape,
          device=self._patch.grad.device,
          dtype=self._patch.grad.dtype,
      )
  
      with torch.no_grad():
          self._patch[:] = torch.clamp(
              self._patch + gradients,
              min=self.estimator.clip_values[0],
              max=self.estimator.clip_values[1],
          )
  
      return loss
  
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 2 for calling the AdversarialTexturePyTorch obj's underlying member method code with example usage: obj._train_step(videos, target, y_init, foreground, patch_points) and returns: loss