class_docstr: Wrapper class for importing Keras models.
docstr: 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': the sum of the output will be divided by the number of elements in the output,
             'sum': the output will be summed.
  :return: Loss values.
  :rtype: Format as expected by the `model`
docstr_tok: ["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","'",":","the","sum","of","the","output","will","be","divided","by","the","number","of","elements","in","the","output",",","'sum","'",":","the","output","will","be","summed",".",":","return",":","Loss","values",".",":","rtype",":","Format","as","expected","by","the","`","model","`"]
code: def compute_loss(  # pylint: disable=W0221
      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': the sum of the output will be divided by the number of elements in the output,
                 'sum': the output will be summed.
      :return: Loss values.
      :rtype: Format as expected by the `model`
      """
      if not self._losses:
          raise NotImplementedError(
              "loss method is only supported for keras versions >= 2.3.1"
          )
  
      if self.is_tensorflow:
          import tensorflow.keras.backend as k  # pylint: disable=E0611
      else:
          import keras.backend as k
  
      y = check_and_transform_label_format(y, self.nb_classes)  # type: ignore
  
      # Apply preprocessing
      x_preprocessed, y_preprocessed = self._apply_preprocessing(
          x, y, fit=False
      )
  
      shape_match = [
          i is None or i == j
          for i, j in zip(self._input_shape, x_preprocessed.shape[1:])
      ]
      if not all(shape_match):  # pragma: no cover
          raise ValueError(
              f"Error when checking x: expected preprocessed x to have shape {self._input_shape} but got array with "
              f"shape {x_preprocessed.shape[1:]}."
          )
  
      # Adjust the shape of y for loss functions that do not take labels in one-hot encoding
      if self._reduce_labels:
          y_preprocessed = np.argmax(y_preprocessed, axis=1)
  
      predictions = self._model.predict(x_preprocessed)
  
      if self._orig_loss and hasattr(self._orig_loss, "reduction"):
          prev_reduction = self._orig_loss.reduction
          if hasattr(self._losses, "Reduction"):
              self._orig_loss.reduction = self._losses.Reduction.NONE
          loss = self._orig_loss(y_preprocessed, predictions)
          self._orig_loss.reduction = prev_reduction
      else:
          prev_reduction = []
          predictions = k.constant(predictions)
          y_preprocessed = k.constant(y_preprocessed)
          for loss_function in self._model.loss_functions:
              prev_reduction.append(loss_function.reduction)
              if hasattr(self._losses, "Reduction"):
                  loss_function.reduction = self._losses.Reduction.NONE
          loss = self._loss_function(y_preprocessed, predictions)
          for i, loss_function in enumerate(self._model.loss_functions):
              loss_function.reduction = prev_reduction[i]
  
      loss_value = k.eval(loss)
  
      if reduction == "none":
          pass
      elif reduction == "mean":
          loss_value = np.mean(loss_value, axis=0)
      elif reduction == "sum":
          loss_value = np.sum(loss_value, axis=0)
  
      return loss_value
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  import time
  from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  import six
  from art import config
  from art.estimators.keras import KerasEstimator
  from art.estimators.classification.classifier import ClassifierMixin, ClassGradientsMixin
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 7 for calling the KerasClassifier obj's underlying member method code with example usage: obj.compute_loss(x, y, reduction) and returns: loss_value