code: def get_tensor_spec(t, dynamic_batch=False, name=None):
      """Returns a `TensorSpec` given a single `Tensor` or `TensorSpec`."""
      # pylint: disable=protected-access
      if isinstance(t, type_spec.TypeSpec):
          spec = t
      elif is_extension_type(t):
          # TODO(b/148821952): Should these specs have a name attr?
          spec = t._type_spec
      elif hasattr(t, "_keras_history") and hasattr(
          t._keras_history[0], "_type_spec"
      ):
          return t._keras_history[0]._type_spec
      elif hasattr(t, "shape") and hasattr(t, "dtype"):
          spec = tensor_lib.TensorSpec(
              shape=t.shape, dtype=t.dtype, name=name
          )
      else:
          return None  # Allow non-Tensors to pass through.
  
      if not dynamic_batch:
          return spec
  
      dynamic_batch_spec = copy.deepcopy(spec)
      # RaggedTensorSpec only has a private _shape.
      shape = dynamic_batch_spec._shape
      if shape.rank is not None and shape.rank > 0:
          shape_list = shape.as_list()
          shape_list[0] = None
          dynamic_batch_spec._shape = tensor_shape.TensorShape(
              shape_list
          )
      return dynamic_batch_spec
  
imports: import collections
  import copy
  import numpy
  from tensorflow.python.data.experimental.ops import cardinality
  from tensorflow.python.distribute.coordinator import cluster_coordinator
  from tensorflow.python.eager import context
  from tensorflow.python.framework import composite_tensor
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.framework import type_spec
  from tensorflow.python.keras import backend
  from tensorflow.python.keras.engine import keras_tensor
  from tensorflow.python.keras.utils import object_identity
  from tensorflow.python.keras.utils import tf_contextlib
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.ops.ragged import ragged_tensor
  from tensorflow.python.ops.ragged import ragged_tensor_value
  from tensorflow.python.util import nest
label_desc: Use image node_id 20 for calling a global function with example usage: get_tensor_spec(t, dynamic_batch, name) and returns: dynamic_batch_spec, spec, t, None