code: def _get_input_outer_ndim(
      layer: tf.keras.layers.Layer, input_spec: types.NestedTensorSpec
  ) -> int:
      """Calculate or guess the number of batch (outer) ndims in `layer`."""
      if isinstance(layer, tf.keras.layers.RNN):
          raise TypeError(
              "Saw a tf.keras.layers.RNN layer nested inside e.g. a keras Sequential "
              "layer.  This is not directly supported.  Please wrap your layer "
              "inside a `tf_agents.keras_layers.RNNWrapper` or use "
              "`tf_agents.networks.Sequential`.  Layer: {}".format(
                  layer
              )
          )
      if isinstance(layer, tf.keras.layers.TimeDistributed):
          return 1 + _get_input_outer_ndim(layer.layer, input_spec)
      if isinstance(layer, tf.keras.Sequential):
          # We don't trust Sequential to give us the right thing if the first layer
          # is e.g. a TimeDistributed.
          return _get_input_outer_ndim(layer.layers[0], input_spec)
  
      layer_input_spec = layer.input_spec
  
      if layer_input_spec is None:
          return 1
  
      outer_ndim = layer_input_spec.ndim
      if outer_ndim is None:
          outer_ndim = layer_input_spec.min_ndim
  
      if outer_ndim is None:
          return 1
  
      if input_spec:
          input_spec = tf.nest.flatten(input_spec)[0]
          if outer_ndim >= input_spec.shape.ndims:
              # We can capture the "outer batch size" as the diff between the
              # expected input rank and the rank of the non-batched spec passed in the
              # input_spec.
              return outer_ndim - input_spec.shape.ndims
  
      # Empty input_spec.
      return 1
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import typing
  import six
  import tensorflow
  import tensorflow_probability
  from tf_agents.distributions import utils
  from tf_agents.networks import layer_utils
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
  from tf_agents.utils import object_identity
  from tensorflow.python.trackable import base
  from tensorflow.python.util import tf_decorator
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 5 for calling a global function with example usage: _get_input_outer_ndim(layer, input_spec) and returns: int, unknown, _get_input_outer_ndim, int, int, unknown