code: def _run_forward_to_layer(
      model: tf.keras.models.Model,
      layer: tf.keras.layers.Layer,
      orig_call: Callable,
      x: Union[List[np.ndarray], np.ndarray],
      forward_kwargs: Optional[dict] = None,
      run_to_layer_inputs: bool = False,
  ) -> tf.Tensor:
      """
      Executes a forward call from the model input to an internal layer output.
  
      Parameters
      ----------
      model
          `tensorflow` model.
      layer
          Starting layer for the forward call.
      orig_call
          Original `call` method of the layer.
      x
          Model's inputs.
      forward_kwargs
          Input keyword args.
      run_to_layer_inputs
          If ``True``, the layer's inputs are returned. If ``False``, the layer's output's are returned.
  
      Returns
      -------
      Output of the given layer.
  
      """
      if forward_kwargs is None:
          forward_kwargs = {}
  
      def take_layer(layer):
          """
          Stores the layer's outputs internally to the layer's object.
  
          """
  
          def decorator(func):
              def wrapper(*args, **kwargs):
                  # Store the result of `layer.call` internally.
                  layer.inp = args
                  layer.result = func(*args, **kwargs)
                  # Return the result to continue with the forward pass.
                  return layer.result
  
              return wrapper
  
          layer.call = decorator(layer.call)
  
      # inp = tf.zeros((x.shape[0], ) + model.input_shape[1:])
      take_layer(layer)
      _ = model(x, **forward_kwargs)
      layer_inp = layer.inp
      layer_out = layer.result
  
      delattr(layer, "inp")
      delattr(layer, "result")
      layer.call = orig_call
  
      if run_to_layer_inputs:
          return layer_inp
      else:
          return layer_out
  
imports: import copy
  import logging
  import string
  import warnings
  from enum import Enum
  from typing import Callable, List, Optional, Tuple, Union, cast
  import numpy
  import tensorflow
  from alibi.api.defaults import DEFAULT_DATA_INTGRAD, DEFAULT_META_INTGRAD
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.utils.approximation_methods import approximation_parameters
label_desc: Use image node_id 5 for calling a global function with example usage: _run_forward_to_layer(model, layer, orig_call, x, forward_kwargs, run_to_layer_inputs) and returns: layer_inp, layer_out, wrapper, layer