yolov5 onnx 推理代码
Posted 洪流之源
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了yolov5 onnx 推理代码相关的知识,希望对你有一定的参考价值。
onnx_yolov5_inference.py
import os
import cv2
import time
import onnxruntime as ort
import numpy as np
from common import pad_to_square
from common import save_tensor
from common import decode
from common import non_max_suppression
from common import draw_result
anchors = [[10,13], [16,30], [33,23],
[30,61], [62,45], [59,119],
[116,90],[156,198], [373,326]]
# 模型输入尺寸
model_input_h = 640
model_input_w = 640
# 目标置信度阈值
obj_conf_thresh = 0.3
# nms iou阈值
nms_iou_thresh = 0.5
# 类别数量
classes_num = 1
# 类别标签
class_label = (\'o\')
if __name__ == \'__main__\':
image_name = \'B5D95V.jpg\'
test_image_path = \'./data/test_images/{}\'.format(image_name)
onnx_model_path = \'./models/onnx/best_20210531_sim.onnx\'
tensor_output_dir = \'./data/output_tensor\'
# 读取图片并转换到RGB图像格式,
# 注意opencv图像维度顺序为:
# shape[0]=h, sh
以上是关于yolov5 onnx 推理代码的主要内容,如果未能解决你的问题,请参考以下文章
Pytorch的pth模型转onnx,再用ONNX Runtime调用推理(附python代码)
模型推理加速系列BERT加速方案对比 TorchScript vs. ONNX