-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
33 lines (23 loc) · 815 Bytes
/
predict.py
File metadata and controls
33 lines (23 loc) · 815 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
32
33
import os
import glob
import sys
import json
import numpy as np
import torch
from asl.model import Net, loadImg
def main():
labelMap = ['T', 'F', 'X', 'C', 'space', 'delete', 'R', 'E', 'K', 'O', 'W', 'P', 'J',
'U', 'L', 'nothing', 'A', 'S', 'B', 'Z', 'I', 'M', 'G', 'H', 'V', 'N', 'Y', 'D', 'Q']
net = torch.load('./asl/asl_predict.pth', map_location='cpu')
imagepath = os.path.join('./inputs', os.listdir('./inputs')[0])
testImage = loadImg(imagepath)
output = net.forward(testImage)[0]
value, index = torch.max(output, 0)
predLabel = str(labelMap[index])
# print(value, index)
os.remove(imagepath)
return predLabel
if __name__ == '__main__':
sys.stdout.write(main())
sys.stdout.flush()
# print(main())