Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import tensorflow as tf
import sys
image_path = sys.argv[1]
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
label_lines = [line.rstrip() for line in tf.gfile.GFile('labels.txt')]
with tf.gfile.FastGFile('graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
_ = tf.import_graph_def(graph_def, name='')
with tf.Session() as session:
softmax_tensor = session.graph.get_tensor_by_name('final_result:0')
predictions =, {'DecodeJpeg/contents:0': image_data})
predictions_by_confidence = predictions[0].argsort()[-len(predictions[0]):][::-1]
for node_id in predictions_by_confidence:
human_readable = label_lines[node_id]
score = predictions[0][node_id]
print('%s (score = %5f)' % (human_readable, score))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.