class_docstr: Implementation of the adversarial patch attack for square and rectangular images and videos in PyTorch.
  
  | Paper link: https://arxiv.org/abs/1712.09665
code: def _loss(
      self,
      images: "torch.Tensor",
      target: "torch.Tensor",
      mask: Optional["torch.Tensor"],
  ) -> "torch.Tensor":
      import torch
  
      if isinstance(target, torch.Tensor):
          predictions, target = self._predictions(images, mask, target)
  
          if self.use_logits:
              loss = torch.nn.functional.cross_entropy(
                  input=predictions,
                  target=torch.argmax(target, dim=1),
                  reduction="mean",
              )
          else:
              loss = torch.nn.functional.nll_loss(
                  input=predictions,
                  target=torch.argmax(target, dim=1),
                  reduction="mean",
              )
  
      else:
          patched_input = self._random_overlay(
              images, self._patch, mask=mask
          )
          patched_input = torch.clamp(
              patched_input,
              min=self.estimator.clip_values[0],
              max=self.estimator.clip_values[1],
          )
  
          loss = self.estimator.compute_loss(x=patched_input, y=target)
  
      if (
          (not self.targeted and self._optimizer_string != "pgd")
          or self.targeted
          and self._optimizer_string == "pgd"
      ):
          loss = -loss
  
      return loss
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import math
  from typing import Any, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  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.utils import check_and_transform_label_format, is_probability, to_categorical
  from art.summary_writer import SummaryWriter
label_desc: Use image node_id 4 for calling the AdversarialPatchPyTorch obj's underlying member method code with example usage: obj._loss(images, target, mask) and returns: loss