code: def assert_compatible(spec, value):
      """Asserts that values are compatible with given specs.
  
      Args:
        spec: A structure compatible with `tf.nest`, with `tf.TensorSpec` values.
        value: A collection of values that should be compatible with `spec`. Must be
          the same structure as `spec`.
  
      Raises:
        TypeError: If `spec` does not contain only `tf.TensorSpec` objects.
        ValueError: If the provided `value` is not compatible with `spec`.
      """
  
      def validate_spec(s, v):
          if not isinstance(s, tf.TensorSpec):
              raise TypeError(
                  "Each value in `spec` must be a tf.TensorSpec."
              )
          return s.is_compatible_with(v)
  
      compatible = tf.nest.map_structure(validate_spec, spec, value)
      if not all(tf.nest.flatten(compatible)):
          raise ValueError(
              "The provided value is not compatible with spec."
          )
  
file_path: model-optimization/tensorflow_model_optimization/python/core/internal/tensor_encoding/utils/py_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import enum
  import numpy
  import six
  import tensorflow
  import tree
label_desc: Use image node_id 5 for calling a global function with example usage: assert_compatible(spec, value) and returns: s