code: def _get_const_nodes(fn):
      from tensorflow.core.framework import graph_pb2, node_def_pb2
  
      new_graph = graph_pb2.GraphDef()
      constant_nodes = set()
      constant_node_num_outputs = {}
      generated_nodes = [
          k for k, v in fn.graph.items() if v.original_node is None
      ]
      const_nodes_in_this_graph = const_determined_nodes(
          fn.graph, set(generated_nodes)
      )
      # we can only run TF on nodes with outputs since we must evaluate
      # tensors and not ops
      const_nodes_in_this_graph = [
          i
          for i in const_nodes_in_this_graph
          if fn.graph[i].op != "NoOp"
      ]
      constant_nodes = constant_nodes.union(
          set(const_nodes_in_this_graph)
      )
  
      # topological sort const nodes
      topsort = []
      topsort_set = set()
      while len(const_nodes_in_this_graph) > 0:
          for n in const_nodes_in_this_graph:
              input_names = fn.graph[n].inputs
              if len(set(input_names).difference(topsort_set)) == 0:
                  topsort.append(n)
                  topsort_set.add(n)
  
          const_nodes_in_this_graph = set(
              const_nodes_in_this_graph
          ).difference(topsort_set)
  
      for node in topsort:
          new_node = node_def_pb2.NodeDef()
          new_node.CopyFrom(fn.graph[node].original_node)
          if "_class" in new_node.attr:
              del new_node.attr["_class"]
          del new_node.input[:]
          new_node.input.extend(fn.graph[node].inputs)
          if "_output_shapes" in fn.graph[node].attr:
              constant_node_num_outputs[node] = len(
                  fn.graph[node].attr["_output_shapes"]
              )
          else:
              constant_node_num_outputs[node] = 1
          new_graph.node.extend([new_node])
          del new_node
      gc.collect()
      return new_graph, list(constant_nodes), constant_node_num_outputs
  
file_path: coremltools/coremltools/converters/mil/frontend/tensorflow/tf_graph_pass/constant_propagation.py
imports: import gc
  from distutils.version import StrictVersion
  import tensorflow
  from coremltools import _logger
  from coremltools._deps import _get_version
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.mil.types.type_mapping import numpy_val_to_builtin_val
  from ..basic_graph_ops import const_determined_nodes
label_desc: Use image node_id 1 for calling a global function with example usage: _get_const_nodes(fn) and returns: new_graph,  list,  constant_node_num_outputs