def generate(  # type: ignore  # pylint: disable=signature-differs
        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)

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