code: def run_compare_tf(
      graph,
      feed_dict,
      output_nodes,
      use_cpu_only=False,
      frontend_only=False,
      frontend="tensorflow",
      backend="nn_proto",
      atol=1e-04,
      rtol=1e-05,
      validate_shapes_only=False,
      freeze_graph=False,
  ):
      """
      Utility function to convert and compare a given TensorFlow 1.x model.
  
      Parameters
      ----------
      graph: tf.Graph
          TensorFlow 1.x model in tf.Graph format.
      feed_dict: dict of (tf.placeholder, np.array)
          Dict of placeholder and value pairs representing inputs.
      output_nodes: tf.node or list[tf.node]
          List of names representing outputs.
      use_cpu_only: bool
          If true, use CPU only for prediction, otherwise, use GPU also.
      frontend_only: bool
          If true, skip the prediction call, only validate conversion.
      frontend: str
          Frontend to convert from.
      backend: str
          Backend to convert to.
      atol: float
          The absolute tolerance parameter.
      rtol: float
          The relative tolerance parameter.
      validate_shapes_only: bool
          If true, skip element-wise value comparision.
      """
      (
          proto,
          input_key_values,
          output_names,
          output_nodes,
      ) = tf_graph_to_proto(
          graph, feed_dict, output_nodes, frontend, backend
      )
  
      if frontend_only:
          return
  
      if not isinstance(output_nodes, (tuple, list)):
          output_nodes = [output_nodes]
  
      if freeze_graph:
          model_dir = tempfile.mkdtemp()
          graph_def_file = os.path.join(model_dir, "tf_graph.pb")
          checkpoint_file = os.path.join(model_dir, "tf_model.ckpt")
          static_model_file = os.path.join(model_dir, "tf_static.pb")
          coreml_model_file = os.path.join(
              model_dir, "coreml_model.mlmodel"
          )
  
          with tf.Session(graph=graph) as sess:
              sess.run(tf.global_variables_initializer())
              tf_outputs = sess.run(output_nodes, feed_dict=feed_dict)
  
              tf.train.write_graph(
                  sess.graph, model_dir, graph_def_file, as_text=False
              )
              saver = tf.train.Saver()
              saver.save(sess, checkpoint_file)
              freeze_g(
                  input_graph=graph_def_file,
                  input_saver="",
                  input_binary=True,
                  input_checkpoint=checkpoint_file,
                  output_node_names=",".join(
                      [n.op.name for n in output_nodes]
                  ),
                  restore_op_name="save/restore_all",
                  filename_tensor_name="save/Const:0",
                  output_graph=static_model_file,
                  clear_devices=True,
                  initializer_nodes="",
              )
          graph = load_tf_pb(static_model_file)
  
          # Need to convert again using frozen graph
          (
              proto,
              input_key_values,
              output_names,
              output_nodes,
          ) = tf_graph_to_proto(
              graph, feed_dict, output_nodes, frontend, backend
          )
      else:
          with tf.Session(graph=graph) as sess:
              sess.run(tf.global_variables_initializer())
              tf_outputs = sess.run(output_nodes, feed_dict=feed_dict)
      expected_outputs = {
          name: val for name, val in zip(output_names, tf_outputs)
      }
  
      if validate_shapes_only:
          compare_shapes(
              proto, input_key_values, expected_outputs, use_cpu_only
          )
      else:
          compare_backend(
              proto,
              input_key_values,
              expected_outputs,
              use_cpu_only,
              atol=atol,
              rtol=rtol,
              also_compare_shapes=True,
          )
  
      return proto
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/frontend/tensorflow/test/testing_utils.py
imports: import six
  from coremltools import TensorType
  import pytest
  from coremltools.converters.mil.testing_utils import compare_shapes, compare_backend
  from coremltools.converters.mil.testing_reqs import converter
  from tensorflow.python.framework import dtypes
  import tempfile
  import os
  from tensorflow.python.tools.freeze_graph import freeze_graph
label_desc: Use image node_id 6 for calling a global function with example usage: run_compare_tf(graph, feed_dict, output_nodes, use_cpu_only, frontend_only, frontend, backend, atol, rtol, validate_shapes_only, freeze_graph) and returns: proto