yolov5 servitization optimization (#262)

* yolov5 split pre and post process

* yolov5 postprocess

* yolov5 postprocess
This commit is contained in:
heliqi
2022-09-21 05:22:39 -05:00
committed by GitHub
parent 463ee0a088
commit a8e447f225
9 changed files with 194 additions and 77 deletions

View File

@@ -17,9 +17,10 @@ import os
import sys
from .c_lib_wrap import (Frontend, Backend, FDDataType, TensorInfo, Device,
is_built_with_gpu, is_built_with_ort,
FDTensor, is_built_with_gpu, is_built_with_ort,
is_built_with_paddle, is_built_with_trt,
get_default_cuda_directory)
from .runtime import Runtime, RuntimeOption
from .model import FastDeployModel
from . import c_lib_wrap as C

View File

@@ -23,7 +23,8 @@ class Runtime:
runtime_option._option), "Initialize Runtime Failed!"
def infer(self, data):
assert isinstance(data, dict), "The input data should be type of dict."
assert isinstance(data, dict) or isinstance(
data, list), "The input data should be type of dict or list."
return self._runtime.infer(data)
def num_inputs(self):

View File

@@ -37,6 +37,31 @@ class YOLOv5(FastDeployModel):
return self._model.predict(input_image, conf_threshold,
nms_iou_threshold)
@staticmethod
def preprocess(input_image,
size=[640, 640],
padding_value=[114.0, 114.0, 114.0],
is_mini_pad=False,
is_no_pad=False,
is_scale_up=False,
stride=32,
max_wh=7680.0,
multi_label=True):
return C.vision.detection.YOLOv5.preprocess(
input_image, size, padding_value, is_mini_pad, is_no_pad,
is_scale_up, stride, max_wh, multi_label)
@staticmethod
def postprocess(infer_result,
im_info,
conf_threshold=0.25,
nms_iou_threshold=0.5,
multi_label=True,
max_wh=7680.0):
return C.vision.detection.YOLOv5.postprocess(
infer_result, im_info, conf_threshold, nms_iou_threshold,
multi_label, max_wh)
# 一些跟YOLOv5模型有关的属性封装
# 多数是预处理相关可通过修改如model.size = [1280, 1280]改变预处理时resize的大小前提是模型支持
@property