def compute_loss(self, x: np.ndarray, y: np.ndarray, reduction: str = "none", **kwargs) -> np.ndarray:
        """
        Compute the loss of the neural network for samples `x`.

        :param x: Samples of shape (nb_samples, nb_features) or (nb_samples, nb_pixels_1, nb_pixels_2,
                  nb_channels) or (nb_samples, nb_channels, nb_pixels_1, nb_pixels_2).
        :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices
                  of shape `(nb_samples,)`.
        :param reduction: Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'.
                   'none': no reduction will be applied
                   'mean': Not supported
                   'sum': Not supported
        :return: Loss values.
        :rtype: Format as expected by the `model`
        """
        import tensorflow.compat.v1 as tf

        if self.learning is not None:
            self.feed_dict[self.learning] = False

        if self.loss is None:  # pragma: no cover
            raise TypeError("The loss placeholder `loss` is required for computing losses, but it is not defined.")

        if reduction == "none":
            _loss = self._loss
        elif reduction == "mean":
            _loss = tf.reduce_mean(self._loss)
        elif reduction == "sum":
            _loss = tf.reduce_sum(self._loss)
        else:
            raise ValueError("Value of `reduction` not recognized.")

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

        # Create feed_dict
        feed_dict = {self.input_ph: x_preprocessed, self.labels_ph: y}
        feed_dict.update(self.feed_dict)

        # Run train step
        loss_value = self._sess.run(_loss, feed_dict=feed_dict)

        return loss_value

        Compute the loss of the neural network for samples `x`.

        :param x: Samples of shape (nb_samples, nb_features) or (nb_samples, nb_pixels_1, nb_pixels_2,
                  nb_channels) or (nb_samples, nb_channels, nb_pixels_1, nb_pixels_2).
        :param y: Target values (class labels) one-hot-encoded of shape `(nb_samples, nb_classes)` or indices
                  of shape `(nb_samples,)`.
        :param reduction: Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'.
                   'none': no reduction will be applied
                   'mean': Not supported
                   'sum': Not supported
        :return: Loss values.
        :rtype: Format as expected by the `model`
        
art/estimators/classification/tensorflow.py