-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlabel.py
27 lines (22 loc) · 817 Bytes
/
label.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import tensorflow as tf
import os
import sys
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
input_layer = 'DecodeJpeg/contents:0'
output_layer = 'final_result:0'
#Reading Image data from command line argument
image = tf.gfile.FastGFile(sys.argv[1], 'rb').read()
#Reading labels file
labels = [line.rstrip() for line in tf.gfile.GFile("labels_hotdog.txt")]
with tf.gfile.FastGFile("graph_hotdog.pb", 'rb') as f:
g_def = tf.GraphDef()
g_def.ParseFromString(f.read())
tf.import_graph_def(g_def, name='')
with tf.Session() as sess:
soft_tensor=sess.graph.get_tensor_by_name(output_layer)
predict, = sess.run(soft_tensor, {input_layer: image})
top = predict.argsort()[-2:][::-1]
for x in top:
result = labels[x]
score = predict[x]
print('%s = %.5f ' % (result, score))