code: def _get_target_prediction(targets, model):
      # type: (Optional[list], Model) -> K.variable
      """
      Get a prediction ID based on ``targets``,
      from the model ``model`` (with a rank 2 tensor for its final layer).
      Returns a rank 1 K.variable tensor.
      """
      if isinstance(targets, list):
          # take the first prediction from the list
          if len(targets) == 1:
              target = targets[0]
              _validate_target(target, model.output_shape)
              predicted_idx = K.constant([target], dtype="int64")
          else:
              raise ValueError(
                  "More than one prediction target "
                  "is currently not supported "
                  "(found a list that is not length 1): "
                  "{}".format(targets)
              )
      elif targets is None:
          predicted_idx = K.argmax(model.output, axis=-1)
      else:
          raise TypeError(
              'Invalid argument "targets" (must be list or None): %s'
              % targets
          )
      return predicted_idx
  
file_path: eli5/eli5/keras/gradcam.py
imports: from __future__ import absolute_import
  from typing import Union, Optional, Tuple, List
  import numpy
  import keras
  import keras.backend
  from keras.models import Model
  from keras.layers import Layer
label_desc: Use image node_id 4 for calling a global function with example usage: _get_target_prediction(targets, model) and returns: predicted_idx