class_docstr: Wrapper class for importing Keras models.
code: def _init_class_gradients(
      self, label: Optional[Union[int, List[int], np.ndarray]] = None
  ) -> None:
      # pylint: disable=E0401
      if self.is_tensorflow:
          import tensorflow.keras.backend as k  # pylint: disable=E0611
      else:
          import keras.backend as k
  
      if len(self._output.shape) == 2:
          nb_outputs = self._output.shape[1]
      else:  # pragma: no cover
          raise ValueError(
              "Unexpected output shape for classification in Keras model."
          )
  
      if label is None:
          logger.debug(
              "Computing class gradients for all %i classes.",
              self.nb_classes,
          )
          if not hasattr(self, "_class_gradients"):
              class_gradients = [
                  k.gradients(self._predictions_op[:, i], self._input)[
                      0
                  ]
                  for i in range(nb_outputs)
              ]
              self._class_gradients = k.function(
                  [self._input], class_gradients
              )
  
      else:
          if isinstance(label, int):
              unique_labels = [label]
          else:
              unique_labels = np.unique(label).tolist()
          logger.debug(
              "Computing class gradients for classes %s.",
              str(unique_labels),
          )
  
          if not hasattr(self, "_class_gradients_idx"):
              self._class_gradients_idx = [
                  None for _ in range(nb_outputs)
              ]
  
          for current_label in unique_labels:
              if self._class_gradients_idx[current_label] is None:
                  class_gradients = [
                      k.gradients(
                          self._predictions_op[:, current_label],
                          self._input,
                      )[0]
                  ]
                  self._class_gradients_idx[current_label] = k.function(
                      [self._input, k.learning_phase()], class_gradients
                  )
  
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 16 for calling the KerasClassifier obj's underlying member method code with example usage: obj._init_class_gradients(label) without return types