-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
44 lines (35 loc) · 1.19 KB
/
test.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
from time import time
import matplotlib.pyplot as plt
from openvino.runtime import Core
from src.utils import *
#! ------------ Modify only these informations -----------------
modelPath = "src/Models/best_openvino_model/quantized_best.xml"
imagePath = "src/Assets/testImage.jpg"
imageSize = 480
#! -------------------------------------------------------------
# Initialize model
core = Core()
model = core.read_model(modelPath)
device = "CPU"
compiledModel = core.compile_model(model, device)
# Read and process input image
frame = cv2.cvtColor(cv2.imread(imagePath), cv2.COLOR_BGR2RGB)
outputLayer = compiledModel.output(0)
frame = letterbox(frame, new_shape=(imageSize, imageSize))[0]
inputTensor = np.expand_dims(frame, 0)
input_hw = frame.shape[:2]
# Inference quantized model
timeList = []
for _ in range(200):
s = time()
result = compiledModel(inputTensor)[outputLayer]
e = time()
timeList.append(e-s)
print("Test FPS: ", 1/np.mean(timeList))
# Process outputs of model
detections = postprocess(result, input_hw, frame)
for i in detections[0]["det"]:
cv2.rectangle(frame, (int(i[0]), int(i[1])), (int(i[2]), int(i[3])), (255, 0, 0), 3)
# Show image
plt.imshow(frame)
plt.show()