栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

YOLOV5 使用 ML.NET ONNX 在C#部署

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

YOLOV5 使用 ML.NET ONNX 在C#部署

YOLOV5 使用 ML.NET ONNX 在C#部署
  • 前言
  • 一、生成dll调用库
    • 1.安装.NET core SDK
    • 2.Nuget安装 ML ONNX Running Time
    • 3.生成Dll库文件
  • 二、winform 程序调用dll
    • 1.新建winform 程序
    • 2.安装Nuget 包
    • 3.下载官网的onnx模型文件
    • 4.添加引用
    • 5. 程序修改
      • 5.1 模型初始化
      • 5.2 模型推断
  • 三、实际的效果


前言 参考[https://github.com/mentalstack/yolov5-net](https://github.com/mentalstack/yolov5-net)的实现
一、生成dll调用库 1.安装.NET core SDK

.NET Core 3.1 SDK (v3.1.416) - Windows x64

2.Nuget安装 ML ONNX Running Time

3.生成Dll库文件


二、winform 程序调用dll 1.新建winform 程序 2.安装Nuget 包

3.下载官网的onnx模型文件

模型文件下载地址

4.添加引用

5. 程序修改 5.1 模型初始化
scorer = new YoloScorer("Assets/Weights/yolov5s.onnx");
5.2 模型推断
        private void button1_Click(object sender, EventArgs e)
        {

           
            var image = Image.FromFile(@"Assets/test3.jpg");
            DateTime T_start = DateTime.Now;
            List predictions = scorer.Predict(image);

            var graphics = Graphics.FromImage(image);

            foreach (var prediction in predictions) // iterate predictions to draw results
            {
                double score = Math.Round(prediction.Score, 2);

                graphics.DrawRectangles(new Pen(prediction.Label.Color, 1),
                    new[] { prediction.Rectangle });

                var (x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);

                graphics.DrawString($"{prediction.Label.Name} ({score})",
                    new Font("Arial", 16, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
                    new PointF(x, y));
            }

            image.Save("Assets/result.jpg");
            this.pictureBox1.Image = image;
            DateTime T_end = DateTime.Now;
            TimeSpan T_esp = T_end - T_start;
            this.label1.Text = T_esp.TotalMilliseconds.ToString();

        }
三、实际的效果

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/903683.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号