-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathclassify_npyfile_case1.py
52 lines (43 loc) · 1.46 KB
/
classify_npyfile_case1.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
51
52
import numpy, sys
from PIL import Image
f = open('classes.txt')
classes = f.readlines()
classes = [f[:-1] for f in classes]
clsnum = len(classes)
scores_ = numpy.load(sys.argv[2])
f = open(sys.argv[1])
lines = f.readlines()
vid = [int(v.split(' ')[-1][:-1]) for v in lines]
imfiles = [v.split(' ')[0] for v in lines]
numR = scores_.shape[1]/ (clsnum+1)
if (len(scores_) > numR) or (len(vid) > numR):
print 'Please input the info. of a single sample.'
exit()
scores = numpy.ones( (numR, len(scores_[0])) )
for i in range( len(vid) ):
scores[ vid[ i ] ] = scores_[ i ]
for i in range(0,len(scores)):
for j in range(0,numR):
for k in range(0,clsnum):
scores[i][ j * (clsnum+1) + k ] = scores[i][ j * (clsnum+1) + k ] / scores[i][ j * (clsnum+1) + clsnum ]
scores[i][ j * (clsnum+1) + clsnum ] = 0
clsnum = (clsnum+1)
s = numpy.ones(clsnum*numR)
for i in range(numR):
for j in range(clsnum):
for k in range(numR):
idx = i + k
if idx > (numR-1):
idx = idx - numR
s[ i * clsnum + j ] = s[ i * clsnum + j ] * scores[ k ][ idx * clsnum + j ]
cls = numpy.argmax(s) % clsnum
max_ang = numpy.argmax(s) / clsnum
print '***********************'
print '** predicted:', classes[ cls ], '**'
print '***********************'
# show image
images = []
for i in imfiles:
images.append( numpy.array( Image.open(i) ) )
images = numpy.concatenate( images, axis=1 )
Image.fromarray(images).show()