code: def main(argv):
      if flags.FLAGS.mode == "visual":
          visual_mode(
              mode_type=flags.FLAGS.type,
              pattern_name=flags.FLAGS.name,
              pattern_idx=flags.FLAGS.idx,
              graph_path=flags.FLAGS.graph_path,
          )
      elif flags.FLAGS.mode == "save_pattern":
          if flags.FLAGS.name is None:
              raise ValueError(
                  "Flags 's pattern name({}) cann't be None.".format(
                      flags.FLAGS.name
                  )
              )
          elif flags.FLAGS.dir == None:
              raise ValueError(
                  "Flags 's pattern dir({}) cann't be None.".format(
                      flags.FLAGS.dir
                  )
              )
          else:
              with Session() as sess:
                  graph_def = RegistPattern.get_patterns(
                      flags.FLAGS.name
                  )[flags.FLAGS.idx]
                  model_path = (
                      flags.FLAGS.dir + "/" + flags.FLAGS.name + ".pb"
                  )
                  with open(model_path, "wb") as f:
                      f.write(graph_def.SerializeToString())
              sess.close()
      elif flags.FLAGS.mode == "simplify":
          if flags.FLAGS.graph_path is None:
              raise ValueError(
                  "Flags 's graph_path({}) cann't be None.".format(
                      flags.FLAGS.graph_path
                  )
              )
          else:
              with Session() as sess:
                  with open(flags.FLAGS.graph_path, "rb") as f:
                      graph_def = tf.GraphDef()
                      graph_def.ParseFromString(f.read())
                      g_in = tf.import_graph_def(graph_def)
                      global_variables_initializer().run()
                      # graph_summary = GraphSummary(graph_def=sess.graph_def)
                      # graph_summary.Summary()
                      outs = flags.FLAGS.outs.split(",")
                      graph_def = (
                          graph_util.convert_variables_to_constants(
                              sess, sess.graph_def, outs
                          )
                      )
                      graph_summary = GraphSummary(graph_def=graph_def)
                      graph_summary.Summary()
                      graph_def_name = flags.FLAGS.graph_path.split(
                          "/"
                      )[-1]
                      model_path = (
                          flags.FLAGS.dir + "/" + graph_def_name
                      )
                      with open(model_path, "wb") as f:
                          f.write(graph_def.SerializeToString())
      else:
          for pattern_name in RegistPattern.Patterns().keys():
              print(
                  "Registered Pattern name: {} with {} different GraphDef.".format(
                      pattern_name,
                      len(RegistPattern.get_patterns(pattern_name)),
                  )
              )
  
file_path: delta/gcompiler/python/delta_infer/visual_pattern.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import sys
  import socket
  import tempfile
  import shutil
  import netron
  import tensorflow
  from tensorboard import program, default
  from absl import app
  from absl import flags
  from .subgraphs import *
label_desc: Use image node_id 3 for calling a global function with example usage: main(argv) without return types