forked from shouxieai/tensorRT_Pro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_centernet.py
More file actions
30 lines (23 loc) · 872 Bytes
/
test_centernet.py
File metadata and controls
30 lines (23 loc) · 872 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
import os
import cv2
import numpy as np
import trtpy as tp
# change current workspace
os.chdir("../workspace/")
# 如果执行出错,请删掉 ~/.trtpy的缓存模型
# rm -rf ~/.trtpy,重新下载
engine_file = "centernet_r18_dcn.fp32.trtmodel"
if not os.path.exists(engine_file):
tp.compile_onnx_to_file(5, tp.onnx_hub("centernet_r18_dcn"), engine_file)
model = tp.CenterNet(engine_file)
image = cv2.imread("inference/car.jpg")
bboxes = model.commit(image).get()
print(f"{len(bboxes)} objects")
for box in bboxes:
print(box)
left, top, right, bottom = map(int, [box.left, box.top, box.right, box.bottom])
cv2.rectangle(image, (left, top), (right, bottom), tp.random_color(box.class_label), 5)
os.makedirs("single_inference", exist_ok=True)
saveto = "single_inference/centernet.car.jpg"
print(f"Save to {saveto}")
cv2.imwrite(saveto, image)