code: def test_freeze_and_convert_matmul_graph():
      # testing : https://coremltools.readme.io/docs/tensorflow-1#export-as-frozen-graph-and-convert
  
      import tensorflow as tf
  
      graph = tf.Graph()
      with graph.as_default():
          x = tf.placeholder(tf.float32, shape=[None, 20], name="input")
          W = tf.Variable(tf.truncated_normal([20, 10], stddev=0.1))
          b = tf.Variable(tf.ones([10]))
          y = tf.matmul(x, W) + b
          output_names = [y.op.name]
  
      import tempfile
      import os
      from tensorflow.python.tools.freeze_graph import 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")
      frozen_graph_file = os.path.join(model_dir, "tf_frozen.pb")
  
      with tf.Session(graph=graph) as sess:
          # initialize variables
          sess.run(tf.global_variables_initializer())
          # save graph definition somewhere
          tf.train.write_graph(
              sess.graph, model_dir, graph_def_file, as_text=False
          )
          # save the weights
          saver = tf.train.Saver()
          saver.save(sess, checkpoint_file)
  
          # take the graph definition and weights
          # and freeze into a single .pb frozen graph file
          freeze_graph(
              input_graph=graph_def_file,
              input_saver="",
              input_binary=True,
              input_checkpoint=checkpoint_file,
              output_node_names=",".join(output_names),
              restore_op_name="save/restore_all",
              filename_tensor_name="save/Const:0",
              output_graph=frozen_graph_file,
              clear_devices=True,
              initializer_nodes="",
          )
      print(
          "Tensorflow frozen graph saved at {}".format(
              frozen_graph_file
          )
      )
  
      mlmodel = ct.convert(frozen_graph_file)
      # optionally, you can save model to disk
      # mlmodel.save(frozen_graph_file.replace("pb", "mlmodel"))
      import shutil
  
      try:
          shutil.rmtree(model_dir)
      except:
          pass
  
imports: from os import getcwd, chdir
  from shutil import rmtree
  from os.path import exists
  from tempfile import mkdtemp
  import pytest
  import numpy
  import coremltools
  import os
  from coremltools._deps import _HAS_TF_1, _HAS_TF_2, _HAS_TORCH, MSG_TF1_NOT_FOUND, MSG_TF2_NOT_FOUND, MSG_TORCH_NOT_FOUND
label_desc: Use image node_id 4 for calling the TestTensorFlow1ConverterExamples obj's underlying member method code with example usage: obj.test_freeze_and_convert_matmul_graph() without return types