def compute_loss(self, x: np.ndarray, y: np.ndarray, **kwargs) -> np.ndarray:
        """
        Compute the loss.

        :param x: Sample input with shape as expected by the model.
        :param y: Targets of format `list[dict[str, np.ndarray]]`, one for each input image. The fields of the dict are
                  as follows:
                    - boxes [N, 4]: the boxes in [y1, x1, y2, x2] format, with 0 <= x1 < x2 <= W and 0 <= y1 < y2 <= H.
                    - labels [N]: the labels for each image in TensorFlow format.
                    - scores [N]: the scores or each prediction.
        :return: np.float32 representing total loss.
        """

        import tensorflow as tf

        # Apply preprocessing
        x_preprocessed, _ = self._apply_preprocessing(x, y=None, fit=False)
        x_preprocessed = tf.convert_to_tensor(x_preprocessed)

        groundtruth_boxes_list = [tf.convert_to_tensor(y[i]["boxes"]) for i in range(x.shape[0])]

        groundtruth_classes_list = [
            tf.one_hot(groundtruth_class, self._model.num_classes, on_value=1.0, off_value=0.0)
            for groundtruth_class in [tf.convert_to_tensor(y[i]["labels"]) for i in range(x.shape[0])]
        ]

        groundtruth_weights_list = [[1] * len(y[i]["labels"]) for i in range(x.shape[0])]

        self._model.provide_groundtruth(
            groundtruth_boxes_list=groundtruth_boxes_list,
            groundtruth_classes_list=groundtruth_classes_list,
            groundtruth_weights_list=groundtruth_weights_list,
        )

        preprocessed_images, true_image_shapes = self._model.preprocess(x_preprocessed)
        predictions = self._model.predict(preprocessed_images, true_image_shapes)
        losses = self._model.loss(predictions, true_image_shapes)

        loss = None
        for loss_name in self.attack_losses:
            if loss is None:
                loss = losses[loss_name].numpy()
            else:
                loss = loss + losses[loss_name].numpy()

        total_loss = np.array([loss])

        return total_loss

        Compute the loss.

        :param x: Sample input with shape as expected by the model.
        :param y: Targets of format `list[dict[str, np.ndarray]]`, one for each input image. The fields of the dict are
                  as follows:
                    - boxes [N, 4]: the boxes in [y1, x1, y2, x2] format, with 0 <= x1 < x2 <= W and 0 <= y1 < y2 <= H.
                    - labels [N]: the labels for each image in TensorFlow format.
                    - scores [N]: the scores or each prediction.
        :return: np.float32 representing total loss.
        
art/estimators/object_detection/tensorflow_v2_faster_rcnn.py