def _train_step(
        self,
        videos: "torch.Tensor",
        target: list[dict[str, "torch.Tensor"]],
        y_init: "torch.Tensor",
        foreground: "torch.Tensor" | None,
        patch_points: np.ndarray | None,
    ) -> "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

        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.
        
art/attacks/evasion/adversarial_texture/adversarial_texture_pytorch.py