0%

轻量级目标检测模型部署对比测试

选用的模型有:

这里,我们采用统一的格式onnx ,使用三种方式来加载推理:

  • onnxruntime
  • openvino
  • opencv

加载模型的代码如下:

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
# author: sunshine
# datetime:2022/8/17 下午2:53
import onnxruntime
import cv2
from openvino.runtime import Core


class ONNXPredict:
def __init__(self, onnx_path):
self.session = onnxruntime.InferenceSession(onnx_path)

def do_inference(self, img_in):
# Compute
input_name = self.session.get_inputs()[0].name
outputs = self.session.run(None, {input_name: img_in})
return outputs


class OpencvPredict:
def __init__(self, onnx_path, w, h):
self.net = cv2.dnn.readNet(onnx_path)
self.w = w
self.h = h

def do_inference(self, img_in):
blob = cv2.dnn.blobFromImage(img_in, 1 / 255.0, (self.w, self.h))
self.net.setInput(blob)
outs = self.net.forward(self.net.getUnconnectedOutLayersNames())
return outs


class OpenvinoPredict:
def __init__(self, engine_path):
ie = Core()
model = ie.read_model(engine_path)
self.compiled_model = ie.compile_model(model=model, device_name='CPU')

def do_inference(self, img_in):
result_infer = self.compiled_model([img_in])
return list(result_infer.values())

具体三种轻量级目标检测模型的推理代码见:https://github.com/fushengwuyu/light_objectdetect

推理时间统计(用本地笔记本测试 CPU: i7-7700HQ,8核):

模型 onnx openvino opencv Resolution
nanodet_plus 0.0842 0.0503 0.2394 416*416
FastestDet 0.0200 0.0182 0.0747 512*512
yolo-fastestv2 0.0125 0.01271 0.0380 352*352

硬件资源占用(边缘服务器:6核2G,带不动openvino,所以没测试)

模型 CPU(onnx) memory(onnx) CPU(opencv) memory(opencv)
nanodet_plus 360% 6.3% 412% 6.7%
FastestDet 310% 4.7% 270% 4.7%
yolo-fastestv2 306% 5.4% 335% 5.7%

边缘服务器推理时间统计:

模型 onnx opencv
nanodet_plus 0.5430 0.6136
FastestDet 0.1653 0.2123
yolo-fastestv2 0.1653 0.1064

最终统计如下:

模型 mAP size run time(onnx) cpu memory model size
nanodet_plus-m-1.5x 34.1 416 0.5430 360% 6.3% 9.5M
FastestDet 25.3 352 0.1653 310% 4.7% 960K
yolo-fastestv2 24.1 352 0.1653 306% 5.4% 958K
nanodet_plus-m 30.4 416 0.3575 341% 6.0% 4.6M