[C#]使用C#部署yolov10的目标检测tensorrt模型

server/2024/10/16 2:07:40/

【测试通过环境】

win10 x64
vs2019
cuda11.7+cudnn8.8.0
TensorRT-8.6.1.6
opencvsharp==4.9.0
.NET Framework4.7.2

NVIDIA GeForce RTX 2070 Super

cuda和tensorrt版本和上述环境版本不一样的需要重新编译TensorRtExtern.dll,TensorRtExtern源码地址:TensorRT-CSharp-API/src/TensorRtExtern at TensorRtSharp2.0 · guojin-yan/TensorRT-CSharp-API · GitHub

Windows版 CUDA安装参考:Windows版 CUDA安装_win cuda安装-CSDN博客

【特别注意】

tensorrt依赖不同硬件需要自己从onnx转换tensorrt,转换就是调用api实现,流程如下

下载源码:https://github.com/THU-MIG/yolov10

并按照官方要求安装好环境:

conda create -n yolov10 python=3.9
conda activate yolov10
pip install -r requirements.txt
pip install -e .

下载yolov10n.pt模型:https://huggingface.co/jameslahm/yolov10n

将Pytorch导出onnx:

# End-to-End ONNX
yolo export model=jameslahm/yolov10{n/s/m/b/l/x} format=onnx opset=13 simplify

将onnx转成tensorrt模型:

trtexec --onnx=yolov10n/s/m/b/l/x.onnx --saveEngine=yolov10n/s/m/b/l/x.engine --fp16

最后将转换好的tenorrt模型使用C#源码即可

【视频演示和解说】

使用C#部署yolov10的目标检测tensorrt模型_哔哩哔哩_bilibili测试环境:win10 x64vs2019cuda11.7+cudnn8.8.0TensorRT-8.6.1.6opencvsharp==4.9.0.NET Framework4.7.2特别注意:环境一定要对上,否则无法正常运行,具体可以参考我的博客和录制视频。博客地址:https://blog.csdn.net/FL1623863129/article/details/139682652, 视频播放量 1、弹幕量 0、点赞数 0、投硬币枚数 0、收藏人数 0、转发人数 0, 视频作者 未来自主研究中心, 作者简介 未来自主研究中心,相关视频:用C#部署yolov8的tensorrt模型进行目标检测winform最快检测速度,使用纯opencv部署yolov8目标检测模型onnx,[深度学习][目标检测][面试提问]Batch Normalization批归一化,使用C++部署yolov9的tensorrt模型进行目标检测,labelme json转yolo工具用于目标检测训练数据集使用教程,基于yolov8+bytetrack实现目标追踪视频演示,【yolo标题党的无奈】TRT快不等于TRT快- -!,C++使用纯opencv部署yolov9的onnx模型,yolov5自动标注工具自动打标签目标检测自动标注使用教程,C#实现全网yolov7目前最快winform目标检测icon-default.png?t=N7T8https://www.bilibili.com/video/BV17S411P7he/?vd_source=989ae2b903ea1b5acebbe2c4c4a635ee

【部分实现源码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FIRC;
using OpenCvSharp;
using TrtCommon;
using TensorRtSharp;
using TensorRtSharp.Custom;
using System.Diagnostics;namespace WindowsFormsApp1
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){Yolov10Det detector = new Yolov10Det("yolov10n.engine");Mat image1 = Cv2.ImRead(@"E:\person.jpg");List<DetResult> detResults = detector.Predict(new List<Mat> { image1 });Mat re_image1 = Visualize.DrawDetResult(detResults[0], image1);Cv2.ImShow("image1", re_image1);Cv2.WaitKey(0);}private void button2_Click(object sender, EventArgs e){}private void button3_Click(object sender, EventArgs e){Yolov10Det detector = new Yolov10Det("yolov10n.engine");VideoCapture capture = new VideoCapture(0);if (!capture.IsOpened()){Console.WriteLine("video not open!");return;}Mat frame = new Mat();var sw = new Stopwatch();int fps = 0;while (true){capture.Read(frame);if (frame.Empty()){Console.WriteLine("data is empty!");break;}sw.Start();List<DetResult> detResults = detector.Predict(new List<Mat> { frame });Mat resultImg = Visualize.DrawDetResult(detResults[0], frame);sw.Stop();fps = Convert.ToInt32(1 / sw.Elapsed.TotalSeconds);sw.Reset();Cv2.PutText(resultImg, "FPS=" + fps, new OpenCvSharp.Point(30, 30), HersheyFonts.HersheyComplex, 1.0, new Scalar(255, 0, 0), 3);//显示结果Cv2.ImShow("Result", resultImg);int key = Cv2.WaitKey(10);if (key == 27)break;}capture.Release();}}
}

【演示源码下载地址】https://download.csdn.net/download/FL1623863129/89432589

注意源码提供上面对应环境的dll,只需要安装上面一样cuda+cudnn和tensorrt版本即可正常运行。如果您不安装一样版本不能正常运行。此时需要重新编译TensorRtExtern.dll,此外由于tensorrt依赖硬件不一样电脑可能无法共用tensorrt模型,所以必须要重新转换onnx模型到engine才可以运行。


http://www.ppmy.cn/server/49042.html

相关文章

在 Ubuntu 上取消登录密码和锁屏功能的简易指南

你可以使用终端命令来直接设置取消登录密码和锁屏功能。以下是具体步骤&#xff1a; 取消登录密码 打开终端。编辑 /etc/gdm3/custom.conf 文件&#xff1a;sudo nano /etc/gdm3/custom.conf在 [daemon] 部分下&#xff0c;添加或修改以下行&#xff1a;AutomaticLoginEnable…

【Python】数据处理:SQLite操作

使用 Python 与 SQLite 进行交互非常方便。SQLite 是一个轻量级的关系数据库&#xff0c;Python 标准库中包含一个名为 sqlite3 的模块&#xff0c;可以直接使用。 import sqlite3数据库连接和管理 连接到 SQLite 数据库。如果数据库文件不存在&#xff0c;则创建一个新数据库…

python中装饰器的用法

最近发现装饰器是一个非常有意思的东西&#xff0c;很高级&#xff01; 允许你在不修改函数或类的源代码的情况下&#xff0c;为它们添加额外的功能或修改它们的行为。装饰器本质上是一个接受函数作为参数的可调用对象&#xff08;通常是函数或类&#xff09;&#xff0c;并返…

[数据集][目标检测]足球场足球运动员身份识别足球裁判员数据集VOC+YOLO格式312张4类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;312 标注数量(xml文件个数)&#xff1a;312 标注数量(txt文件个数)&#xff1a;312 标注类别…

课设--学生成绩管理系统

欢迎来到 Papicatch的博客 文章目录 &#x1f349;技术核心 &#x1f349;引言 &#x1f348;标识 &#x1f348;背景 &#x1f348;项目概述 &#x1f348; 文档概述 &#x1f349;可行性分析的前提 &#x1f348;项目的要求 &#x1f348;项目的目标 &#x1f348;…

LLMs,即大型语言模型

LLMs&#xff0c;即大型语言模型&#xff0c;是一类基于深度学习的人工智能模型&#xff0c;它们通过海量的数据和大量的计算资源进行训练&#xff0c;可以理解和生成自然语言。LLMs的核心架构是Transformer&#xff0c;其关键在于自注意力机制&#xff0c;使得模型能够同时对…

qt Json操作

说明 该例子说明了字符串转Json对象&#xff0c;再从Json对象转字符串 代码 #include <QCoreApplication> #include <QTextCodec> #include <iostream> #include <QDebug> #include <QJsonDocument> #include <QJsonObject>using names…

perl use HTTP::Server::Simple 轻量级 http server

cpan -i HTTP::Server::Simple 返回&#xff1a;已是 up to date. 但是我在 D:\Strawberry\perl\site\lib\ 找不到 HTTP\Server 手工安装&#xff1a;下载 HTTP-Server-Simple-0.52.tar.gz 解压 tar zxvf HTTP-Server-Simple-0.52.tar.gz cd D:\perl\HTTP-Server-Simple-…