code: def explain_prediction_keras(
      model,  # type: Model
      doc,  # type: np.ndarray
      targets=None,  # type: Optional[list]
      layer=None,  # type: Optional[Union[int, str, Layer]]
      image=None,
  ):
      # type: (...) -> Explanation
      """
      Explain the prediction of a Keras classifier with the Grad-CAM technique.
  
      We explicitly assume that the model's task is classification, i.e. final output is class scores.
  
      :param keras.models.Model model:
          Instance of a Keras neural network model,
          whose predictions are to be explained.
  
      :param numpy.ndarray doc:
          An input to ``model`` whose prediction will be explained.
  
          Currently only numpy arrays are supported.
  
          The tensor must be of suitable shape for the ``model``.
  
          Check ``model.input_shape`` to confirm the required dimensions of the input tensor.
  
  
          :raises TypeError: if ``doc`` is not a numpy array.
          :raises ValueError: if ``doc`` shape does not match.
  
      :param targets:
          Prediction ID's to focus on.
  
          *Currently only the first prediction from the list is explained*.
          The list must be length one.
  
          If None, the model is fed the input image and its top prediction
          is taken as the target automatically.
  
  
          :raises ValueError: if ``targets`` is a list with more than one item.
          :raises TypeError: if ``targets`` is not list or None.
      :type targets: list[int], optional
  
      :param layer:
          The activation layer in the model to perform Grad-CAM on:
          a valid keras layer name, layer index, or an instance of a Keras layer.
  
          If None, a suitable layer is attempted to be retrieved.
          For best results, pick a layer that:
  
          * has spatial or temporal information (conv, recurrent, pooling, embedding)
            (not dense layers).
          * shows high level features.
          * has large enough dimensions for resizing over input to work.
  
  
          :raises TypeError: if ``layer`` is not None, str, int, or keras.layers.Layer instance.
          :raises ValueError: if suitable layer can not be found.
          :raises ValueError: if differentiation fails with respect to retrieved ``layer``.
      :type layer: int or str or keras.layers.Layer, optional
  
  
      See :func:`eli5.explain_prediction` for more information about the ``model``,
      ``doc``, and ``targets`` parameters.
  
  
      Other arguments are passed to concrete implementations
      for image and text explanations.
  
  
      Returns
      -------
        expl : :class:`eli5.base.Explanation`
          An :class:`eli5.base.Explanation` object for the relevant implementation.
      """
      # Note that this function should only do dispatch
      # and no other processing
      if image is not None or _maybe_image(model, doc):
          return explain_prediction_keras_image(
              model,
              doc,
              image=image,
              targets=targets,
              layer=layer,
          )
      else:
          return explain_prediction_keras_not_supported(model, doc)
  
imports: from __future__ import absolute_import
  from typing import Union, Optional, Callable, Tuple, List, TYPE_CHECKING
  import numpy
  import keras
  import keras.backend
  from keras.models import Model
  from keras.layers import Layer
  from keras.layers import Conv2D, MaxPooling2D, AveragePooling2D, GlobalMaxPooling2D, GlobalAveragePooling2D
  from keras.preprocessing.image import array_to_img
  from eli5.base import Explanation, TargetExplanation
  from eli5.explain import explain_prediction
  from .gradcam import gradcam, gradcam_backend
label_desc: Use image node_id 1 for calling a global function with example usage: explain_prediction_keras(model, doc, targets, layer, image) and returns: explain_prediction_keras_image, explain_prediction_keras_not_supported