-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.py
35 lines (23 loc) · 854 Bytes
/
main.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
# -*- coding:utf-8 -*-
import os
import time
import cv2
from infer import YoloDetector
load_start = time.time()
# instance
yolo_infer = YoloDetector(trt_plan="./model.plan", gpu_id=0)
load_end = time.time()
print("Model load cost: %.4f s" % (load_end - load_start))
for img_name in os.listdir("./images"):
img_path = os.path.join("./images", img_name)
img = cv2.imread(img_path, cv2.IMREAD_COLOR)
infer_start = time.time()
bboxes, masks = yolo_infer.inference(img)
infer_end = time.time()
print("Infer image %s cost %d ms." % (img_name, (infer_end - infer_start) * 1000))
YoloDetector.draw_image(img, bboxes, masks)
save_dir = "./output/"
if not os.path.exists(save_dir):
os.makedirs(save_dir)
cv2.imwrite(save_dir + "_" + img_name, img)
yolo_infer.release()