code: def get_tensor_spec(t, dynamic_batch=False, name=None):
      """Returns a `TensorSpec` given a single `Tensor` or `TensorSpec`."""
      if isinstance(t, tf.TypeSpec):
          spec = t
      elif isinstance(t, tf.__internal__.CompositeTensor):
          # Check for ExtensionTypes
          spec = t._type_spec
      elif hasattr(t, "shape") and hasattr(t, "dtype"):
          spec = tf.TensorSpec(shape=t.shape, dtype=t.dtype, name=name)
      else:
          return None  # Allow non-Tensors to pass through.
  
      if not dynamic_batch:
          return spec
  
      shape = spec.shape
      if shape.rank is None or shape.rank == 0:
          return spec
  
      shape_list = shape.as_list()
      shape_list[0] = None
      shape = tf.TensorShape(shape_list)
      spec._shape = shape
      return spec
  
imports: from keras.utils.module_utils import tensorflow
label_desc: Use image node_id 5 for calling a global function with example usage: get_tensor_spec(t, dynamic_batch, name) and returns: spec, spec, spec, None