Open yz2yz opened 1 year ago
@yz2yz 这个问题我记得之前看过,有以下几个问题:
1*3*1280*832
,FD图片大小为1*3*1280*1280
,图片较大肯定预处理以及infer时间都会增加耗时,你的代码将auto参数设置为Fasle跟FD对齐model.preprocessor.size = [1280, 1280]
之后postprocessor = fd.vision.detection.YOLOv5Postprocessor()
postprocessor.conf_threshold = 0.3
postprocessor.nms_threshold = 0.3
然后再重测一下
@wjj19950828 谢谢,如您指导的一样,改成auto=False,速度和fd差不多了;什么时候fd支持letterbox的auto=True预处理呢?测试情况如云盘,谢谢! 链接:https://pan.baidu.com/s/1c7bm9uzjAfByPF_RqBb_kg 提取码:bvwz
完整脚本和测试图片,网盘: 链接:https://pan.baidu.com/s/1wK9psssA7mL71bof4RJeSQ 提取码:7a3p
环境
问题描述
针对相同的yolov5导出的onnx模型,先预加载运行一次,然后再运行10次计算平均时间, torch的推理时间约为0.0132秒,fastdeploy的推理时间约为0.023秒。请问下,该如何配置优化。
fastdeploy测试脚本:
''' 车牌对象识别 ''' import os import cv2 import psutil from PIL import Image import fastdeploy as fd from common import is_en_fp16, set_en_fp16, get_gpuid, get_most_idle_gpu, plot_one_box, merge_iou import numpy as np import time
resnet_model = None conf_thres = 0.3 iou_thres = 0.3 weights = 'weights/plates.onnx' trtfile = 'weights/plates.trt' names = ['plate'] sel_color = (12,16,255)
def load_model(): global resnet_model, names, colors, imgsz if resnet_model: return
def get_plate_rects(img0:np.ndarray, draw=False): ''' 得到里程表的边框,一个图片最多一个 ''' if isinstance(img0, Image.Image): img0 = np.array(img0)
if name == 'main': set_en_fp16(True)
torch测试脚本:
''' 车牌对象识别 ''' import os import cv2 import torch import random import numpy as np from models.experimental import attempt_load from utils.general import check_img_size, non_max_suppression, scale_coords from utils.dataloaders import letterbox import time from utils.plots import plot_one_box import psutil
resnet_model = None conf_thres = 0.3 iou_thres = 0.3
stride = 32
dohalf = False augment = False
imgsz = 640
stride = 64 imgsz = 1280 weights = 'weights/plates.pt' device = torch.device("cuda" if torch.cuda.is_available() else "cpu") names = [] colors = []
def load_model(): global resnet_model, names, colors, imgsz if resnet_model: return
def get_img(img0:np.ndarray): img = letterbox(img0, imgsz, stride=stride)[0]
def get_plate_rects(img0:np.ndarray, draw=False): load_model()
img0 = np.array(org_img)
if name == 'main': fname = 'imgs/b5125c60-4dcd-4cdf-998a-d418591e041a.jpg'
fname = 'imgs/123456.jpg'