title: Tensorflow Inception_Resnet_V2 Classify Image
body: <p>I trained an inception_resnet_v2 model for the flowers images following the README at <a href="https://github.com/tensorflow/models/tree/master/slim" rel="nofollow">https://github.com/tensorflow/models/tree/master/slim</a></p>
  
  <p>I got my graph.pbtxt file out of this after training with which I converted to a graph.pb file with the following code:</p>
  
  <pre><code>import tensorflow as tf
  from google.protobuf import text_format
  
  def convert_pbtxt_to_graphdef(filename):
    """Returns a `tf.GraphDef` proto representing the data in the given pbtxt file.
  
    Args:
      filename: The name of a file containing a GraphDef pbtxt (text-formatted
        `tf.GraphDef` protocol buffer data).
  
    Returns:
      A `tf.GraphDef` protocol buffer.
    """
    with tf.gfile.FastGFile(filename, 'r') as f:
      graph_def = tf.GraphDef()
  
      file_content = f.read()
  
      # Merges the human-readable string in `file_content` into `graph_def`.
      text_format.Merge(file_content, graph_def)
    return graph_def
  
  with tf.gfile.FastGFile('/foo/bar/workspace/results/graph.pb', 'wb') as f:
      f.write(convert_pbtxt_to_graphdef('/foo/bar/workspace/results/graph.pbtxt'))
  </code></pre>
  
  <p>After getting this file I tried feeding the trained model a random image using tensorflow's classify_image.py found here: <br><br><a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py" rel="nofollow">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py</a> 
  <br><br>using my .pb, .pbtxt, and my labels file, however, I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "classify_image.py", line 212, in &lt;module&gt;
      tf.app.run()
    File "/usr/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 30, in run
      sys.exit(main(sys.argv[:1] + flags_passthrough))
    File "classify_image.py", line 208, in main
      run_inference_on_image(image)
    File "classify_image.py", line 170, in run_inference_on_image
      softmax_tensor = sess.graph.get_tensor_by_name('softmax:0')
    File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2615, in get_tensor_by_name
      return self.as_graph_element(name, allow_tensor=True, allow_operation=False)
    File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2466, in as_graph_element
      return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
    File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2508, in _as_graph_element_locked
      "graph." % (repr(name), repr(op_name)))
  KeyError: "The name 'softmax:0' refers to a Tensor which does not exist. The operation, 'softmax', does not exist in the graph."
  </code></pre>