title: Tensorflow: Load a .pb file and then save it as a frozen graph issues
body: <p>This question is very similar to this one: <a href="https://stackoverflow.com/questions/49837854/how-do-you-use-freeze-graph-py-in-tensorflow">How do you use freeze_graph.py in Tensorflow?</a>
  but that one has not been answered and I have a different approach to the problem. Thus I would like some input. </p>
  
  <p>I am also trying to load a .pb binary file and then freeze it. This is the code I tried. </p>
  
  <p>Let me know if this gives you any ideas. This does not return errors. It just crashes my jupyter notebook. </p>
  
  <pre><code>import tensorflow as tf
  import sys
  from tensorflow.python.platform import gfile
  
  from tensorflow.core.protobuf import saved_model_pb2
  from tensorflow.python.util import compat
  
  with tf.Session() as sess:
      model_filename ='saved_model.pb' # binary .pb file
      with gfile.FastGFile(model_filename, 'rb') as f:
  
          data = compat.as_bytes(f.read()) # reads binary
          sm = saved_model_pb2.SavedModel() 
          print(sm)
          sm.ParseFromString(data) # parses through the file
          print(sm)
          if 1 != len(sm.meta_graphs):
              print('More than one graph found. Not sure which to write')
              sys.exit(1)
  
          g_in = tf.import_graph_def(sm.meta_graphs[0].graph_def)
          output_graph = "frozen_graph.pb"
  
          # Getting all output nodes for the frozen graph
          output_nodes = [n.name for n in tf.get_default_graph().as_graph_def().node]
          # This not working fully   
          output_graph_def = tf.graph_util.convert_variables_to_constants(
              sess, # The session is used to retrieve the weights
              tf.get_default_graph().as_graph_def(), # The graph_def is used to retrieve the nodes 
              output_nodes# The output node names are used to select the usefull nodes
          ) 
  
          # Finally we serialize and dump the output graph to the filesystem
          with tf.gfile.GFile(output_graph, "wb") as f:
              f.write(output_graph_def.SerializeToString())
          print("%d ops in the final graph." % len(output_graph_def.node))
          print(g_in)
  LOGDIR='.'
  train_writer = tf.summary.FileWriter(LOGDIR)
  train_writer.add_graph(sess.graph)
  </code></pre>
  
  <p>This code should generate a frozen file, but I don't completely understand tensorflow's saving mechanisms. If I take out the freezing the graph part from this code I get and events.out. file that can be read by tensorboard. </p>