-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-test-preds.py
More file actions
executable file
·31 lines (25 loc) · 924 Bytes
/
verify-test-preds.py
File metadata and controls
executable file
·31 lines (25 loc) · 924 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
30
31
import sys
from util import *
import pylab as pl
import numpy as n
import numpy.random as nr
from PIL import Image
from StringIO import StringIO
def print_top5(preds, lnames):
print preds
for i in xrange(len(preds)):
print "Label %d: %s" %(i, lnames[preds[i]])
if __name__ == "__main__":
pred_path = sys.argv[1]
data_path = sys.argv[2]
batch = nr.randint(98) + 3000
data = unpickle(os.path.join(data_path, 'data_batch_%d' % batch))[0]
preds = [n.array([int(x) - 1 for x in l.split(' ')]) for l in open(pred_path).readlines()]
img_idx = nr.randint(len(data))
meta = unpickle(os.path.join(data_path, 'batches.meta'))
lnames = meta['label_names']
print "Batch: %d, img idx: %d" % (batch, img_idx)
img = n.asarray(Image.open(StringIO(data[img_idx])).convert('RGB'))
print_top5(preds[(batch - 3000) * 1024 + img_idx], lnames)
pl.imshow(img)
pl.show()