code: def _flatten_and_check_shape_nested_tensors(
      tensors, specs, num_outer_dims=1
  ):
      """Flatten nested tensors and check their shape for use in other functions."""
      assert_same_structure(
          tensors,
          specs,
          message="Tensors and specs do not have matching structures",
      )
      flat_tensors = tf.nest.flatten(tensors)
      flat_shapes = [spec_shape(s) for s in tf.nest.flatten(specs)]
      for tensor, shape in zip(flat_tensors, flat_shapes):
          if tensor.shape.rank == shape.rank:
              tensor.shape.assert_is_compatible_with(shape)
          elif tensor.shape.rank == shape.rank + num_outer_dims:
              tensor.shape[num_outer_dims:].assert_is_compatible_with(
                  shape
              )
          else:
              raise ValueError(
                  "Tensor does not have the correct dimensions. "
                  "tensor.shape {} expected shape {}".format(
                      tensor.shape, [None] + shape.as_list()
                  )
              )
      return flat_tensors, flat_shapes
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import numbers
  from typing import Optional, Text
  from absl import logging
  import numpy
  from six.moves import zip
  import tensorflow
  from tf_agents.typing import types
  from tf_agents.utils import composite
  import wrapt
  from tensorflow.python.util import nest
label_desc: Use image node_id 15 for calling a global function with example usage: _flatten_and_check_shape_nested_tensors(tensors, specs, num_outer_dims) and returns: flat_tensors,  flat_shapes