Code Monkey home page Code Monkey logo

csharp_deploy_yolov8's Introduction

基于C#(.NET Framework)的YOLO系列深度学习模型部署平台
## 1. 项目介绍

   基于.NET Framework 4.8 开发的深度学习模型部署测试平台,提供了YOLO框架的主流系列模型,包括YOLOv8~v9,以及其系列下的Det、Seg、Pose、Obb、Cls等应用场景,同时支持图像与视频检测。模型部署引擎使用的是OpenVINO™、TensorRT、ONNX runtime以及OpenCV DNN,支持CPU、IGPU以及GPU多种设备推理。

  其中,OpenVINO™以及TensorRT的C#接口均为自行开发,项目链接为:

OpenVINO™ C# API :

https://github.com/guojin-yan/OpenVINO-CSharp-API.git

TensorRT C# API :

https://github.com/guojin-yan/TensorRT-CSharp-API.git

  演示视频:

  C#&YOLO系列深度学习模型部署平台页面主要包括四个区域,分别为:模型选择和加载区域、推理区域、输入图像展示区域以及输出结果图像展示区域。如下图所示:

  如下图所示,演示的是使用YOLOv5 Det模型的推理情况,

  同样的方式,我们可以实现多种模型在不同平台的上的推理,如下图所示:

2. 支持模型

  项目在开发时,同时开发了YOLOv5~v9以及YOLO World等YOLO系列模型,模型部署工具使用的是OpenVINO 、TensorRT 、ONNX runtime、OpenCV DNN,但有一些模型部署工具对模型的算子存在不支持情况,因此,对该项目中所使用的所有模型进行了测试,如下表所示:

Model OpenVINO CPU OpenVINO GPU TensorRT GPU ONNX runtime CPU ONNX runtime GPU OpenCV DNN
YOLOv5 Det
YOLOv5 Seg
YOLOv5 Cls
YOLOv6 Det
YOLOv7 Det
YOLOv8 Det
YOLOv8 Seg
YOLOv8 Pose
YOLOv8 Obb
YOLOv8 Cls
YOLOv9 Det
YOLOv9 Seg
YOLO World

3. 时间测试

  在开发的模型部署平台上进行时间测试,当前的测试环境为:

  • CPU:11th Intel Core i7-1165G7 2.8GHz
  • IGPU:Intel Iris Xe Graphics
  • GPU:NVIDIA GeForce RTX 2060

在同一环境下,对其中一些模型进行了测试,如下表所示:

Model OpenVINO CPU OpenVINO IGPU TensorRT GPU ONNX runtime CPU ONNX runtime GPU OpenCV DNN
YOLOv5s Det 53.78 ms 28.84 ms 22.95 ms 95.68 ms 29.22 ms 178.53 ms
YOLOv5s Seg 119.53 ms 43.49 ms 31.17 ms 144.68 ms 42.27 ms 500.26 ms
YOLOv6s Det 98.66 ms 43.50 ms 19.93 ms 147.14 ms 25.90 msd 155.20 ms
YOLOv8s Det 77.06 ms 37.54 ms 20.04 ms 134.05 ms 25.82 ms 191.34 ms
YOLOv8s Seg 105.55 ms 48.45 ms 25.91 ms 200.01 ms 37.24 ms 532.16 ms

  通过测试结果可以看出:

  • 在GPU上:使用独立显卡加速的TensorRT在推理速度上表现是十分优秀的,但使用集成显卡加速的OpenVINO其推理速度也不容小觑,如果上到英特尔的独立显卡,其推理速度应该还会有很大程度上的提升,而ONNX runtime使用独立显卡加速,其推理性能上与TensorRT相比稍逊色;
  • 在CPU上,OpenVINO 的表现时十分突出的,在使用极少的CPU占用上,其推理速度已经有了很大的提升,而ONNX runtime以及OpenCV DNN占用CPU很大的情况下,其推理速度远不如OpenVINO。

4. 总结

  项目源码目前已经在GitHub上开源,项目链接为:

https://github.com/guojin-yan/YoloDeployCsharp.git

  各位开发者可以根据自己情况加逆行下载,并进行项目配置,其中一些内容的配置可以参考一下文章:

  最后如果各位开发者在使用中有任何问题,欢迎大家与我联系。

csharp_deploy_yolov8's People

Contributors

guojin-yan avatar

Stargazers

 avatar  avatar  avatar  avatar Guanghui  Gu  avatar  avatar Je88e avatar Thomas7 avatar  avatar  avatar  avatar  avatar  avatar  avatar lilanfeng avatar RuiLin Xie avatar Alok Sharma avatar  avatar  avatar  avatar  avatar Fabian Pfister avatar  avatar amanman avatar Ardumine avatar  avatar Frank avatar ChungTak avatar 陈佳欢 avatar 疯风愚雨 avatar  avatar  avatar SunJian  avatar  avatar tooclian avatar  avatar EthanXie avatar maskx avatar  avatar  avatar Gavin Fang avatar Lee Seung Hu avatar geffzhang avatar  avatar  avatar  avatar 十年一梦 avatar standwood avatar  avatar  avatar  avatar Michel avatar E024 avatar  avatar WithSalt avatar alanxinn avatar  avatar  avatar lvaitzxc avatar runoi avatar  avatar ihuo avatar  avatar  avatar  avatar warm tan avatar  avatar  avatar Faraway avatar  avatar  avatar  avatar  avatar  avatar pepure avatar 99年老白干 avatar  avatar Terry Dunlap avatar  avatar  avatar ccyes avatar  avatar shuizhu avatar lwq avatar Mango avatar  avatar Alex zhang avatar  avatar  avatar x9658xc avatar  avatar  avatar  avatar wmx1033 avatar  avatar  avatar Justin avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

csharp_deploy_yolov8's Issues

Problem with Inference at Resolutions Different from 640

Hello,

I'm experiencing an issue with inference when using resolutions different from 640. When training is done with a resolution of 640, the inference works fine. However, with other resolutions, it doesn't work as expected.
I've tested the inference of my models with various resolutions on Python and it works well. However, with this particular application, it doesn't work as expected. The inference is performed, but it detects many bounding boxes scattered all over.

I tested several models with resolutions of 1024 and 2560

2024-05-21_17h28_17

TensorRT 在执行时会跳CUDA lazy loading is not enabled.

如标题,
执行TensorRT时会跳以下错误,
CUDA lazy loading is not enabled. Enabling it can significantly reduce device memory usage and speed up TensorRT initialization.

可以运行但数据加载时间很久,
请问该如何解决。

Yolov5-cls

Hi, thanks for your work

Is it possible to give me a tip to infer Yolov5-cls with this code? I tested it for y5 and I got the strange result.

Thanks in advanced

分类

您好 请问有分类的C++代码吗?

在更新的cuda环境中是否有可能运行?

cuda_12.3.2
cudnn-windows-x86_64-8.9.0.131_cuda12-archive
TensorRT-8.6.1.6.Windows10.x86_64.cuda-12.0

如果有时间可以测试一下吗?
我这里无论如何都不可能成功,我需要对照实验。

不退出程序第二次推理的时候CV里对结果转置发生了异常

推理设备:ONNX runtime
推理模型:Yolov8-pose
异常代码:

        /// <summary>
        /// 结果处理
        /// </summary>
        /// <param name="result">模型预测输出</param>
        /// <returns>模型识别结果</returns>
        public Result process_result(float[] result)
        {
            Mat result_data = new Mat(56, 8400, MatType.CV_32F, result);
------> result_data = result_data.T();
            // 存放结果list
            List<Rect> position_boxes = new List<Rect>();
            List<float> confidences = new List<float>();
            List<PoseData> pose_datas = new List<PoseData>();
            ...

异常信息:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at OpenCvSharp.Internal.NativeMethods.core_MatExpr_toMat(IntPtr, IntPtr)
--------------------------------
   at OpenCvSharp.MatExpr.ToMat()
   at ResultSharp.PoseResult.process_result(Single[])
   at ModelDeployPlatform.FormModelDeployPlat.btn_model_deploy_Click(System.Object, System.EventArgs)
   at System.Windows.Forms.Control.OnClick(System.EventArgs)
   at System.Windows.Forms.Button.OnClick(System.EventArgs)
   at System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs)
   at System.Windows.Forms.Control.WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32)
   at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ButtonBase.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Button.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr, WM, IntPtr, IntPtr)
   at Interop+User32.DispatchMessageW(MSG ByRef)
   at Interop+User32.DispatchMessageW(MSG ByRef)
   at System.Windows.Forms.Application+ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr, msoloop, Void*)
   at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(msoloop, System.Windows.Forms.ApplicationContext)
   at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(msoloop, System.Windows.Forms.ApplicationContext)
   at System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
   at ModelDeployPlatform.Program.Main()

似乎是CV的问题?我尝试了克隆新的Mat并将旧的dispose掉(当次的或上次的都试过),或者使用单独的一个对象而不使用转置后的对象替换转置前的对象都依旧会出现这个异常。

我想请教一下大佬,result传进来的长度只有50400,和这个8400*56的矩阵是个什么关系,只有前6行有数据后面50行全是0吗?如果我希望不使用CV,自己通过二维数组实现,数据该怎么填充?

谢谢大佬

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.