Using graph_metrics.py with a saved graph
<p>I want to view statistics of my model by saving my graph to a file then running <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/graph_metrics.py" rel="nofollow">graph_metrics.py</a>.</p>

<p>I have tried a few different things to write the file, my best effort is:</p>

<pre><code>tf.train.write_graph( session.graph_def, ".", "my_graph", as_text=True )
</code></pre>

<p>But here's what happens:</p>

<pre><code>$ python ./util/graph_metrics.py --noinput_binary --graph my_graph
Traceback (most recent call last):
  File "./util/graph_metrics.py", line 137, in &lt;module&gt;
    tf.app.run()
  File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 30, in run
    sys.exit(main(sys.argv))
  File "./util/graph_metrics.py", line 85, in main
    FLAGS.batch_size)
  File "./util/graph_metrics.py", line 109, in calculate_graph_metrics
    input_tensor = sess.graph.get_tensor_by_name(input_layer)
  File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2531, in get_tensor_by_name
    return self.as_graph_element(name, allow_tensor=True, allow_operation=False)
  File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2385, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2427, in _as_graph_element_locked
    "graph." % (repr(name), repr(op_name)))
KeyError: "The name 'Mul:0' refers to a Tensor which does not exist. The operation, 'Mul', does not exist in the graph."
</code></pre>

<p>Is there a complete working example of saving a graph, then analyzing it with <code>graph_metrics.py</code>?</p>

<p>This process seems to involve a magic incantation that I haven't yet discovered.</p>