-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathasync_api.py
More file actions
executable file
·48 lines (43 loc) · 2.18 KB
/
async_api.py
File metadata and controls
executable file
·48 lines (43 loc) · 2.18 KB
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
#!/usr/bin/env python3
from openvino.inference_engine import IENetwork, IEPlugin
import cv2
import os
import time
model_dir = os.environ['HOME'] + "/model_downloader/object_detection/common/mobilenet-ssd/caffe/FP16/"
model_xml = model_dir + "mobilenet-ssd.xml"
model_bin = model_dir + "mobilenet-ssd.bin"
plugin = IEPlugin(device="MYRIAD")
net = IENetwork(model=model_xml, weights=model_bin)
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
n, c, h, w = net.inputs[input_blob].shape
exec_net = plugin.load(network=net, num_requests=2)
start_time = time.time()
current_inference, next_inference = 0, 1
# for test purpose only
image_number = 200
inferred_images = 0
for i in range(0, image_number):
image = cv2.imread("/opt/intel/computer_vision_sdk/deployment_tools/demo/car.png")
image = cv2.resize(image, (w, h))
image = image.transpose((2, 0, 1))
image = image.reshape((n, c, h, w))
exec_net.start_async(request_id=current_inference, inputs={input_blob: image})
if exec_net.requests[next_inference].wait(-1) == 0:
inferred_images = inferred_images + 1
res = exec_net.requests[next_inference].outputs[out_blob]
#print("infer result: label:%f confidence:%f left:%f top:%f right:%f bottom:%f" %(res[0][0][0][1], res[0][0][0][2], res[0][0][0][3], res[0][0][0][4], res[0][0][0][5], res[0][0][0][6]))
duration = time.time() - start_time
print("inferred frames: " + str(inferred_images) + ", average fps: " + str(inferred_images/duration) +"\r", end = '', flush = False)
current_inference, next_inference = next_inference, current_inference
# one more inference result left to check
if exec_net.requests[next_inference].wait(-1) == 0:
inferred_images = inferred_images + 1
res = exec_net.requests[next_inference].outputs[out_blob]
#print("infer result: label:%f confidence:%f left:%f top:%f right:%f bottom:%f" %(res[0][0][0][1], res[0][0][0][2], res[0][0][0][3], res[0][0][0][4], res[0][0][0][5], res[0][0][0][6]))
duration = time.time() - start_time
print("inferred frames: " + str(inferred_images) + ", average fps: " + str(inferred_images/duration) +"\r", end = '', flush = False)
print()
del exec_net
del net
del plugin