-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpostprocess.py
More file actions
22 lines (19 loc) · 751 Bytes
/
postprocess.py
File metadata and controls
22 lines (19 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!python3
import os.path
import numpy as np
from scipy.special import softmax
from tvm.contrib.download import download_testdata
# download a list of labels
labels_url = 'https://s3.amazonaws.com/onnx-model-zoo/synset.txt'
labels_path = download_testdata(labels_url, 'synset.txt', module='data')
output_file = 'predictions.npz'
with open(labels_path, 'r') as fyl:
labels = [lyn.rstrip() for lyn in fyl]
# open output & read output sensor
if os.path.exists(output_file):
with np.load(output_file) as data:
scores = softmax(data['output_0'])
scores = np.squeeze(scores)
ranks = np.argsort(scores)[::-1]
for rank in ranks[0:5]:
print("class='%s' with possibility=%f" % (labels[rank], scores[rank]))