-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (42 loc) · 1.51 KB
/
app.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import vgg16
import utils
from Nclasses import labels
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
def main():
sess = tf.compat.v1.Session()
images = tf.placeholder(tf.float32, [1, 224, 224, 3])
vgg = vgg16.Vgg16()
vgg.forward(images)
while True:
img_path = input('\nInput the path and image name: ')
if img_path == '0':
print('\nexiting-------------------------\n')
exit(0)
else:
print('\nrunning-------------------------\n')
img_ready = utils.load_image(img_path)
fig=plt.figure(u"Top-5 预测结果")
probability = sess.run(vgg.prob, feed_dict={images:img_ready})
top5 = np.argsort(probability[0])[-1:-6:-1]
print("top5:",top5)
values = []
bar_label = []
for n, i in enumerate(top5):
print("n:",n)
print("i:",i)
values.append(probability[0][i])
bar_label.append(labels[i])
print(i, ":", labels[i], "----", utils.percent(probability[0][i]))
ax = fig.add_subplot(111)
ax.bar(range(len(values)), values, tick_label=bar_label, width=0.5, fc='g')
ax.set_ylabel(u'probabilityit')
ax.set_title(u'Top-5')
for a,b in zip(range(len(values)), values):
ax.text(a, b+0.0005, utils.percent(b), ha='center', va = 'bottom', fontsize=7)
plt.show()
if __name__ == '__main__':
main()