-
Notifications
You must be signed in to change notification settings - Fork 0
/
gluonyolo.py
52 lines (43 loc) · 1.55 KB
/
gluonyolo.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
# See https://gluon-cv.mxnet.io/build/examples_detection/demo_yolo.html#sphx-glr-build-examples-detection-demo-yolo-py
from gluoncv import model_zoo, data, utils
import datetime
import math
import random, string
from time import gmtime, strftime
import os
from six.moves import urllib
import time
import psutil
from time import gmtime, strftime
# YOLO / Gluon / Apache MXNet
#
def yolo(args):
url = args["url"]
start = time.time()
filename = '/tmp/gluoncv_image.jpg'
filepath2 = filename
filepath2, _ = urllib.request.urlretrieve(url, filepath2)
net = model_zoo.get_model('yolo3_darknet53_voc', pretrained=True)
x, img = data.transforms.presets.yolo.load_test(filename, short=512)
class_IDs, scores, bounding_boxs = net(x)
classname = str(class_IDs[0,0,0][0]).strip('<NDArray 1 @cpu(0)>')
classname = classname.strip('\n[')
classname = classname.strip('.]\n')
classname = int(classname)
matchingpct = str(scores[0][0][0]).strip('<NDArray 1 @cpu(0)>')
matchingpct = matchingpct.strip('\n[')
matchingpct = matchingpct.strip('.]\n')
matchingpct = float(matchingpct)
end = time.time()
row = { }
row['class1'] = str(net.classes[classname])
row['pct1'] = '{0}'.format( str((matchingpct) * 100))
row['host'] = os.uname()[1]
row['shape'] = str(x.shape)
row['end'] = '{0}'.format( str(end ))
row['te'] = '{0}'.format(str(end-start))
row['systemtime'] = datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')
row['cpu'] = psutil.cpu_percent(interval=1)
row['memory'] = psutil.virtual_memory().percent
result = row
return result