-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.py
More file actions
29 lines (21 loc) · 757 Bytes
/
Copy pathimage.py
File metadata and controls
29 lines (21 loc) · 757 Bytes
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
import numpy as np
import cv2
img = cv2.imread('../images/typewriter.jpg')
#print(img.shape)
all_rows = open('../model/synset_words.txt').read().strip().split("\n")
classes = [r[r.find(' ') + 1:] for r in all_rows]
net = cv2.dnn.readNetFromCaffe('../model/bvlc_googlenet.prototxt','../model/bvlc_googlenet.caffemodel')
blob = cv2.dnn.blobFromImage(img, 1, (224,224))
net.setInput(blob)
outp = net.forward()
#print(outp)
idx = np.argsort(outp[0])[::-1][:5]
for (i,id) in enumerate(idx):
print('{}. {} ({}): Probability {:.3}%'.format(i+1, classes[id], id, outp[0][id]*100))
#for (i,c) in enumerate(classes):
# if i==4:
# break
# print(i,c)
cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()