code: def run_compare_tf(
      graph,
      feed_dict,
      output_nodes,
      inputs_for_conversion=None,
      compute_unit=ct.ComputeUnit.CPU_ONLY,
      frontend_only=False,
      frontend="tensorflow",
      backend=("neuralnetwork", "fp32"),
      atol=1e-04,
      rtol=1e-05,
      freeze_graph=False,
      tf_outputs=None,
      minimum_deployment_target=None,
  ):
      """
      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.
      inputs_for_conversion: list of coremltools.TensorType() or coremltools.ImageType() objects
          Defaults to None. It is passed as is to the "inputs" argument of the converter.
      compute_unit: Enum[ct.ComputeUnit].
          Compute unit for the coreml model
      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.
      freeze_graph: bool
          If True, use the "tensorflow.python.tools.freeze_graph" function
          to freeze the TF graph prior to conversion. This will ensure that
          all the variables in the graph have been converted to constants.
      tf_outputs: float or list[float]
          If present, use it as TensorFlow predictions
      minimum_deployment_target : coremltools.target enumeration
          It set the minimum_deployment_target argument in the coremltools.convert function.
  
      Return:
          Proto, mlmodel, input dictionary, prediction(if possible)
      """
      if not isinstance(output_nodes, (tuple, list)):
          output_nodes = [output_nodes]
  
      if freeze_graph:
          with tempfile.TemporaryDirectory() as model_dir:
              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"
              )
  
              with tf.Session(graph=graph) as sess:
                  sess.run(tf.global_variables_initializer())
                  if tf_outputs is None:
                      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)
                  output_node_names = get_tf_node_names(
                      output_nodes, mode="outputs"
                  )
                  output_node_names = [
                      name.split(":")[0] for name in output_node_names
                  ]
                  output_op_names = ",".join(output_node_names)
                  freeze_g(
                      input_graph=graph_def_file,
                      input_saver="",
                      input_binary=True,
                      input_checkpoint=checkpoint_file,
                      output_node_names=output_op_names,
                      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)
  
      (
          mlmodel,
          input_key_values,
          output_names,
          output_nodes,
      ) = tf_graph_to_mlmodel(
          graph,
          feed_dict,
          output_nodes,
          frontend,
          backend,
          compute_unit=compute_unit,
          inputs_for_conversion=inputs_for_conversion,
          minimum_deployment_target=minimum_deployment_target,
      )
  
      if (
          frontend_only
          or coremltoolsutils._macos_version() < (10, 13)
          or (
              mlmodel.is_package
              and coremltoolsutils._macos_version() < (12, 0)
          )
      ):
          return mlmodel._spec, mlmodel, input_key_values, None
  
      if tf_outputs is None:
          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)
      }
  
      for k, v in input_key_values.items():
          if isinstance(v, np.ndarray) and issubclass(
              v.dtype.type, np.integer
          ):
              input_key_values[k] = v.astype(
                  float
              )  # Core ML only accepts floats
  
      pred = None
      if not coremltoolsutils._has_custom_layer(mlmodel._spec):
          pred = compare_backend(
              mlmodel,
              input_key_values,
              expected_outputs,
              atol=atol,
              rtol=rtol,
              also_compare_shapes=True,
              dtype=backend[1],
          )
      else:
          print(
              "Skipping model prediction as it has a custom nn layer!"
          )
      return mlmodel._spec, mlmodel, input_key_values, pred
  
imports: import os
  import tempfile
  import numpy
  import pytest
  import coremltools.models.utils
  from coremltools._deps import _HAS_TF_2
  from coremltools.converters.mil.testing_reqs import ct
  from coremltools.converters.mil.testing_utils import compare_backend, ct_convert, validate_minimum_deployment_target
  from tensorflow.python.framework import dtypes
  from tensorflow.python.keras.saving import saving_utils
  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, inputs_for_conversion, compute_unit, frontend_only, frontend, backend, atol, rtol, freeze_graph, tf_outputs, minimum_deployment_target) and returns: mlmodel,  mlmodel,  input_key_values,  pred, mlmodel,  mlmodel,  input_key_values,  None