code: def _optimize_graph(meta_graph_def, signature_def):
      """Optimize `meta_graph_def` using grappler.  Returns a `GraphDef`."""
      # We need to add a collection called 'train_op' so that grappler
      # knows what the outputs are.
      new_meta_graph_def = copy.deepcopy(meta_graph_def)
      fetch_collection = meta_graph_pb2.CollectionDef()
      for tensor_info in list(signature_def.inputs.values()) + list(
          signature_def.outputs.values()
      ):
          fetch_collection.node_list.value.append(tensor_info.name)
  
      new_meta_graph_def.collection_def["train_op"].CopyFrom(
          fetch_collection
      )
      # We freeze the graph, so consider all variables to be readonly.
      new_meta_graph_def.ClearField("saver_def")
      config = config_pb2.ConfigProto()
      rewrite_options = config.graph_options.rewrite_options
      rewrite_options.min_graph_nodes = -1  # do not skip small graphs
      return tf_optimizer.OptimizeGraph(config, new_meta_graph_def)
  
imports: import collections
  import copy
  import os
  import re
  import shlex
  from typing import List, Tuple
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.protobuf import meta_graph_pb2
  from tensorflow.python.client import session
  from tensorflow.python.framework import convert_to_constants
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import versions
  from tensorflow.python.grappler import tf_optimizer
  from tensorflow.python.lib.io import file_io
  from tensorflow.python.ops import array_ops
  from tensorflow.python.platform import sysconfig
  from tensorflow.python.platform import test
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.training import saver
label_desc: Use image node_id 9 for calling a global function with example usage: _optimize_graph(meta_graph_def, signature_def) and returns: tf_optimizer