当前位置: 首页 > news >正文

YoloV10 训练自己的数据集(推理,转化,C#部署)

目录

一、下载

三、开始训练

train.py

detect.py

export.py

超参数都在这个路径下

四、C#读取yolov10模型进行部署推理

如下程序是用来配置openvino

配置好引用后就可以生成dll了  再创建一个控件,作为显示 net framework 4.8版本的

再nuget工具箱里下载 opencvsharp4  以及openvino 

然后主流程代码

效果

我的yolov10 训练源码

C#部署yolov10源码


一、下载

       GitHub - THU-MIG/yolov10: YOLOv10: Real-Time End-to-End Object Detection

或者你可以再浏览器搜索框里直接搜索      yolov10 github

二、环境配置 

下载anaconda 并安装 在网上随意下载一个2022版本的就行

      yolov10和yolov8的文件结构差不多  所以如果你训练过其他的yolov5以上的yolo,你可以直接拷贝环境进行使用,当然你如果想配置gpu   

就需要cuda  cudnn  和 gpu版本的torch    

其他的直接pip install 即可

pip install requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

下方网站中下载你需要的版本下载时要注意对应关系,

cuda和cudnn各个版本的Pytorch下载网页版,onnx,ncnn,pt模型转化工具_cuda国内镜像下载网站-CSDN博客

也可以看我另一篇文章

 Yolov10训练,转化onnx,推理_yolov10转onnx-CSDN博客

三、开始训练

     有一点要注意v10版本其实是从v8版本上面改的 所以v10的预训练模型你需要自行下载  否则就会下载成v8的

    首先标注数据集  在pycharm 中下载labelimg

pip install labelimg -i https://pypi.tuna.tsinghua.edu.cn/simple

下载好后直接在终端输入labelimg 开始标注 训练流程基本和yolov5差不多

在yolov10的根目录下创建一个名为data的文件夹 里面再创建一个data.yaml文件 用于数据集的读取

再在根目录创建三个py文件  分别是  train.py  detect.py    export.py

train.py

from ultralytics import YOLOv10model_yaml_path = "ultralytics/cfg/models/v10/yolov10s.yaml"
#数据集配置文件
data_yaml_path = 'data/data.yaml'
#预训练模型
pre_model_name = 'yolov10s.pt'if __name__ == '__main__':#加载预训练模型model = YOLOv10(model_yaml_path).load(pre_model_name)#训练模型results = model.train(data=data_yaml_path,epochs=450,batch=8,device=0,name='train/exp')# yolo export model="H:\\DL\\yolov10-main\\runs\\detect\\train\\exp\\weights\\best.pt" format=onnx opset=13 simplify

detect.py


from ultralytics import YOLOv10import torch
if  torch.cuda.is_available():device = torch.device("cuda")
else:raise Exception("CUDA is not")model_path = r"H:\\DL\\yolov10-main\\runs\\detect\\train\\exp4\\weights\\best.pt"
model = YOLOv10(model_path)
results = model(source=r'H:\DL\yolov10-main\dataDakeset\two_CD_double\test',name='predict/exp',conf=0.45,save=True,device='0')

export.py

from ultralytics import YOLOv10
model=YOLOv10("H:\\DL\\yolov10-main\\runs\\detect\\train\\exp\\weights\\best.pt")model.export(format='onnx')# 'torchscript, onnx, openvino, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs, paddle'

超参数都在这个路径下

然后设置好参数就可以直接训练了

推理用detect.py 推理   转化用export.py 转化, 转化为哪种模型 就替换即可

四、C#读取yolov10模型进行部署推理

我们需要设定yolov10的模型结构

using OpenCvSharp;
using OpenVinoSharp.Extensions.result;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Yolov10_DLLnet
{public class YOLOv10Det : YOLO{public YOLOv10Det(string model_path, string engine, string device, int categ_nums, float det_thresh, float det_nms_thresh, int input_size): base(model_path, engine, device, categ_nums, det_thresh, det_nms_thresh, new int[] { 1, 3, input_size, input_size },new List<string> { "images" }, new List<int[]> { new int[] { 1, 4 + categ_nums, 8400 } }, new List<string> { "output0" }){}protected override BaseResult postprocess(List<float[]> results){List<Rect> positionBoxes = new List<Rect>();List<int> classIds = new List<int>();List<float> confidences = new List<float>();// Preprocessing output resultsfor (int i = 0; i < results[0].Length / 6; i++){int s = 6 * i;if ((float)results[0][s + 4] > 0.5){float cx = results[0][s + 0];float cy = results[0][s + 1];float dx = results[0][s + 2];float dy = results[0][s + 3];int x = (int)((cx) * m_factor);int y = (int)((cy) * m_factor);int width = (int)((dx - cx) * m_factor);int height = (int)((dy - cy) * m_factor);Rect box = new Rect();box.X = x;box.Y = y;box.Width = width;box.Height = height;positionBoxes.Add(box);classIds.Add((int)results[0][s + 5]);confidences.Add((float)results[0][s + 4]);}}DetResult re = new DetResult();// for (int i = 0; i < positionBoxes.Count; i++){re.add(classIds[i], confidences[i], positionBoxes[i]);}return re;}}
}

然后再设置各项参数 你可以再其中自己定义一个文件 里面写上你需要的类  比如置信度,类别  以及类别数量等等。为后续的dll生成做准备。

如下程序是用来配置openvino

using OpenCvSharp.Dnn;
using OpenCvSharp;
using OpenVinoSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
//using static System.Windows.Forms.Design.AxImporter;namespace Yolov10_DLLnet
{public class Predictor : IDisposable{private Core core;private Model model;private CompiledModel compiled;private InferRequest openvino_infer;private Net opencv_infer;private string engine = null;public Predictor() { }public Predictor(string model_path, string engine, string device){if (model_path == null){throw new ArgumentNullException(nameof(model_path));}this.engine = engine;if (engine == "OpenVINO"){core = new Core();model = core.read_model(model_path);compiled = core.compile_model(model, device);openvino_infer = compiled.create_infer_request();}}public void Dispose(){openvino_infer.Dispose();compiled.Dispose();model.Dispose();core.Dispose();GC.Collect();}public List<float[]> infer(float[] input_data, List<string> input_names, int[] input_size, List<string> output_names, List<int[]> output_sizes){List<float[]> returns = new List<float[]>();var input_tensor = openvino_infer.get_input_tensor();input_tensor.set_data(input_data);openvino_infer.infer();foreach (var name in output_names){var output_tensor = openvino_infer.get_tensor(name);returns.Add(output_tensor.get_data<float>((int)output_tensor.get_size()));}return returns;}}
}

创建一个名为yolo的cs文件用于 将yolov10模型结构做引用

//using Microsoft.VisualBasic.Logging;
using OpenCvSharp;
using OpenVinoSharp.Extensions.model;
using OpenVinoSharp.Extensions.process;
using OpenVinoSharp.Extensions.result;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Yolov10_DLLnet;
using static OpenVinoSharp.Node;namespace Yolov10_DLLnet
{public class YOLO : IDisposable{protected int m_categ_nums;protected float m_det_thresh;protected float m_det_nms_thresh;protected float m_factor;protected int[] m_input_size;protected List<int[]> m_output_sizes;protected List<string> m_input_names;protected List<string> m_output_names;protected List<int> m_image_size = new List<int>();private Predictor m_predictor;Stopwatch sw = new Stopwatch();public YOLO(){m_predictor = new Predictor();}public YOLO(string model_path, string engine, string device, int categ_nums, float det_thresh,float det_nms_thresh, int[] input_size, List<string> input_names, List<int[]> output_sizes, List<string> output_names){m_predictor = new Predictor(model_path, engine, device);m_categ_nums = categ_nums;m_det_thresh = det_thresh;m_det_nms_thresh = det_nms_thresh;m_input_size = input_size;m_output_sizes = output_sizes;m_input_names = input_names;m_output_names = output_names;}float[] preprocess(Mat img){m_image_size = new List<int> { (int)img.Size().Width, (int)img.Size().Height };Mat mat = new Mat();Cv2.CvtColor(img, mat, ColorConversionCodes.BGR2RGB);mat = Resize.letterbox_img(mat, (int)m_input_size[2], out m_factor);mat = Normalize.run(mat, true);return Permute.run(mat);}List<float[]> infer(Mat img){List<float[]> re;float[] data = preprocess(img);re = m_predictor.infer(data, m_input_names, m_input_size, m_output_names, m_output_sizes);return re;}public BaseResult predict(Mat img){List<float[]> result_data = infer(img);BaseResult re = postprocess(result_data);return re;}protected virtual BaseResult postprocess(List<float[]> results){return new BaseResult();}public void Dispose(){m_predictor.Dispose();}public static YOLO GetYolo(string model_type, string model_path, string engine, string device,int categ_nums, float det_thresh, float det_nms_thresh, int input_size){return new YOLOv10Det(model_path, engine, device, categ_nums, det_thresh, det_nms_thresh, input_size);}protected static float sigmoid(float a){float b = 1.0f / (1.0f + (float)Math.Exp(-a));return b;}}
}

配置好引用后就可以生成dll了  再创建一个控件,作为显示 net framework 4.8版本的

再nuget工具箱里下载 opencvsharp4  以及openvino 

然后主流程代码

//using Microsoft.VisualBasic.Logging;
using OpenCvSharp;
using OpenVinoSharp.Extensions.process;
using OpenVinoSharp.Extensions.result;
using OpenVinoSharp.Extensions.utility;
using SharpCompress.Common;
using System.Collections.Generic;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using static OpenVinoSharp.Node;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Point = OpenCvSharp.Point;using Yolov10_DLLnet;
using System.Drawing;
using ZstdSharp.Unsafe;namespace YOLOV10_WinformDemo
{public partial class Form1 : Form{//string filePath = "";private YOLO yolo;public Form1(){InitializeComponent();yolo = new YOLO();//string model_path = "best_0613.onnx";}/// <summary>/// yolov10 onnx模型文件路径/// </summary>private string model_path = "H:\\YCDandPCB_Yolov5_net\\Yolov10_and_Yolov5Seg\\yolov10_Detztest\\YOLOV10_WinformDemo\\bestV10det.onnx";/// <summary>/// 开始识别/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){Stopwatch sw = new Stopwatch();OpenFileDialog openFile = new OpenFileDialog();string filePath = "";if (openFile.ShowDialog() == DialogResult.OK){filePath = openFile.FileName;}//目标检测//string model_path = "best_0613.onnx";classesLabel label = new classesLabel();string model_type = "YOLOv10Det";string engine_type = "OpenVINO";string device = "CPU";//#################   阈值   #######################################float score = label.Score_Threshold;float nms = label.NMS_Threshold;int categ_num = label.classes_count_1;int input_size = label.W_H_size_1;yolo = YOLO.GetYolo(model_type, model_path, engine_type, device, categ_num, score, nms, input_size);//#####################  图片推理阶段  #######################//System.Drawing.Image image = Image.FromFile(openFile.FileName);//string input_path = openFile;Mat img = Cv2.ImRead(filePath);pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(img);sw.Restart();(Mat, BaseResult) re_img = image_predict(img);sw.Stop();pictureBox2.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(re_img.Item1);DetResult detResult = re_img.Item2 as DetResult;for (int i = 0; i < detResult.count; i++){//textBox1.Text = detResult.datas[i].lable;//置信度//textBox2.Text = detResult.datas[i].score.ToString("0.00");int X = detResult.datas[i].box.TopLeft.X;int Y = detResult.datas[i].box.TopLeft.Y;int W = detResult.datas[i].box.Width;int H = detResult.datas[i].box.Height;//textBox3.Text = X.ToString();//textBox4.Text = Y.ToString();//textBox5.Text = W.ToString();//textBox6.Text = H.ToString();Console.WriteLine(X);Console.WriteLine(Y);}// 获取并打印运行时间//TimeSpan ts = sw.Elapsed;textBox7.Text = sw.ElapsedMilliseconds.ToString();}(Mat, BaseResult) image_predict(Mat img, bool is_video = false){Mat re_img = new Mat();//#############################  classes  ###################################classesLabel label = new classesLabel();List<string> class_names = label.class_names;//开始识别,并返回识别结果BaseResult result = yolo.predict(img);result.update_lable(class_names);re_img = Visualize.draw_det_result(result, img);return (re_img, result);}}
}

效果

我的yolov10 训练源码

【免费】yolov10优化代码,包含,train.py,detect.py,export.py脚本以及预训练模型资源-CSDN文库

C#部署yolov10源码

C#部署YoloV10目标检测.netframework4.8,打开即用内有(主程序和dll生成程序)资源-CSDN文库

相关文章:

YoloV10 训练自己的数据集(推理,转化,C#部署)

目录 一、下载 三、开始训练 train.py detect.py export.py 超参数都在这个路径下 四、C#读取yolov10模型进行部署推理 如下程序是用来配置openvino 配置好引用后就可以生成dll了 再创建一个控件&#xff0c;作为显示 net framework 4.8版本的 再nuget工具箱里下载 …...

Science Robotic 内在触觉实现直观的物理人机交互

触觉传感器和电子皮肤是为机器人提供物理交互感的常见设备&#xff0c;但当用于机器人的大面积覆盖时&#xff0c;它们会变得复杂且昂贵。德国宇航中心近期发表的Science Robotics研究工作&#xff0c;使用内部高分辨率关节力扭矩传感器&#xff0c;在机械臂中实现了固有的全身…...

string类(C++)

哈喽各位&#xff01;&#xff0c;久违了&#xff0c;最近怎么样捏&#xff0c;本次进入C的string类&#xff0c;加油加油呀&#xff01; 随记&#xff1a;鼓励创新&#xff0c;宽容失败&#xff01; 1.标准库的string类 1.1string类的了解 string的文献参考链接-->strin…...

【C语言】自定义类型——结构体

目录 一、结构体的类型的声明 二、结构体变量的创建和初始化 三、匿名结构体类型 四、结构体自引用 五、结构体内存对齐 &#xff08;1&#xff09;对齐规则 &#xff08;2&#xff09;计算结构体大小练习 &#xff08;3&#xff09;需要内存对齐的原因 &#xff08;4…...

MySQL练手题--日期连续类型(困难)

一、准备工作 Create table If Not Exists Failed (fail_date date); Create table If Not Exists Succeeded (success_date date); Truncate table Failed; insert into Failed (fail_date) values (2018-12-28); insert into Failed (fail_date) values (2018-12-29); inser…...

【AD24报错】运行DRC后出现 Un-Routed Net Constraint ### Net Not Assigned 的解决方案

AD24在运行PCB设计规则检查&#xff08;DRC&#xff09;后报错 Un-Routed Net Constraint ### Net Not Assigned 的解决方案 一、解决方案二、可能会报错Dead Copper的因素三、可能会报错Un-Routed Net Constraint的因素 Un-Routed Net Constraint ### Net Not Assigned 的解决…...

Linux嵌入式驱动开发指南(速记版)---Linux基础篇

第一章 Ubuntu系统入门 1.1 Linux磁盘管理 1.1.1 Linux磁盘管理基本概念 关键词&#xff1a; Linux 磁盘管理 挂载点 /etc/fstab文件 分区 ls /dev/sd* 联系描述&#xff1a; Linux 磁盘管理体系通过“挂载点”概念替代了 Windows 中的“分区”概念&#xff0c;将硬盘部分以文…...

PDF——压缩大小的方法

方法一&#xff1a;QQ浏览器->格式转换->PDF转纯图PDF...

无监督神经组合优化的扩散模型框架

文章目录 Abstract1. Introduction2. Problem Description2.1 无监督神经组合优化3. Neural Probabilistic Optimization Objective for Approximate Likelihood Models3.1 具有联合变分上界的训练扩散模型Abstract 从离散集合的不可处理分布中进行采样,而不依赖相应的训练数据…...

Web前端开发

首先打开&#xff0c;VS code新建文件夹&#xff0c;命名为index.HTML&#xff0c;然后先对内容进行输入&#xff0c;也就是在波蒂里面进行输入&#xff0c;将社会主义核心价值观的基本内容输入好&#xff0c;然后在页面呈现的效果是这样的 因为有一个alert警告框标签&#xff…...

transformer模型进行英译汉,汉译英

上面是在测试集上的表现 下面是在训练集上的表现 上面是在训练集上的评估效果 这是在测试集上的评估效果,模型是transformer模型,模型应该没问题,以上的是一个源序列没加结束符和加了结束符的情况。 transformer源序列做遮挡填充的自注意力,这就让编码器的输出中每个token的语…...

python 异步读取文件,速度变快了吗

“python 异步读取文件&#xff0c;速度变快了吗” 当我问出这个问题&#xff0c;大部分人第一反应应该是python新人&#xff0c;不懂异步 首先说一下我对异步的理解&#xff1a; asyncio 是 gevent greenlet 的组合gevent 底层使用了libev、selectors 模块&#xff0c;这两…...

【Python】Anaconda插件:Sublime Text中的Python开发利器

上班的时候没人问我苦不苦&#xff0c;下班的时候总有人问为什么走这么早。 Anaconda 是一个专为Sublime Text打造的开源Python开发插件&#xff0c;旨在为开发者提供类似于IDE的丰富功能&#xff0c;提升Python编码效率。该插件提供了代码补全、语法检查、代码片段提示等多项…...

Python酷库之旅-第三方库Pandas(123)

目录 一、用法精讲 546、pandas.DataFrame.ffill方法 546-1、语法 546-2、参数 546-3、功能 546-4、返回值 546-5、说明 546-6、用法 546-6-1、数据准备 546-6-2、代码示例 546-6-3、结果输出 547、pandas.DataFrame.fillna方法 547-1、语法 547-2、参数 547-3、…...

IEEE投稿 IEEE Geoscience and Remote Sensing Letters

IEEE 应用地球观测与遥感专题杂志 journal of Selected Topics in Applied Earth Observations and Remote Sensing IEEE 文章提交流程 撰写文章并准备好图形后&#xff0c;您可以提交文章以供审核。请按照以下步骤完成 IEEE 文章提交流程。 选择目标期刊 如果文章超出期刊范围…...

【华为杯】2024华为杯数模研赛D题 解题思路

题目 大数据驱动的地理综合问题 问题1: 19902020年间中国范围内降水量和土地利用/土地覆被类型的时空演化特征描述? 解题思路 详细分析&#xff1a;此问题要求对降水量&#xff08;连续变化变量&#xff09;和土地利用/覆被&#xff08;离散变化变量&#xff09;进行时空演…...

Ubuntu20.04 搜索不到任何蓝牙设备

电脑信息 联想扬天YangTianT4900k 问题描述 打开蓝牙之后&#xff0c;一直转圈&#xff0c;搜索不到任何蓝牙设备 排查 dmesg | grep -i blue 有如下错误&#xff1a; Bluetooth: hci0: RTL: unknown IC info, lmp subver 8852, hci rev 000b, hci ver 000b lsusb 芯片型号如…...

【2024】MySQL账户管理

当前MySQL版本为&#xff1a; mysql> select version(); ----------- | version() | ----------- | 8.4.2 | ----------- 1 row in set (0.01 sec)目录 创建普通用户为用户授权查看用户权限修改用户权限修改用户密码删除用户 创建普通用户 使用CREATE USER语句创建用户…...

轻量级流密码算法Trivium

轻量级流密码算法Trivium 0x0 Trivium算法简介 Trivium算法是由C&#xff0e;D Canniere和B&#xff0e;Preneel共同设计的一套对称加密算法&#xff0c;Trivium密码算法采用了分组密码和非线性反馈移位寄存器的设计思路。该密码算法总共288比特的内部状态&#xff0c;其中有…...

MapReduce基本原理

目录 整体执行流程​ Map端执行流程 Reduce端执行流程 Shuffle执行流程 整体执行流程 八部曲 读取数据--> 定义map --> 分区 --> 排序 --> 规约 --> 分组 --> 定义reduce --> 输出数据 首先将文件进行切片&#xff08;block&#xff09;处理&#xff…...

32单片机——窗口看门狗

1、WWDG的简介 WWDG&#xff1a;Window watchdog&#xff0c;即窗口看门狗 窗口看门狗本质上是能产生系统复位信号和提前唤醒中断的递减计数器 WWDG产生复位信号的条件&#xff1a; &#xff08;1&#xff09;当递减计数器值从0x40减到0x3F时复位&#xff08;即T6位跳变到0&a…...

【MATLAB代码】制导——平行接近法,三维,目标是运动的,订阅专栏后可直接查看MATLAB源代码

文章目录 运行结果简介代码功能概述运行结果核心模块解析代码特性与优势MATLAB例程代码调整说明相关公式视线角速率约束相对运动学方程导引律加速度指令运动学更新方程拦截条件判定运行结果 运行演示视频: 三维平行接近法导引运行演示 简介 代码功能概述 本代码实现了三维空…...

Java-IO流之打印流详解

Java-IO流之打印流详解 一、打印流概述1.1 什么是打印流1.2 打印流的特点1.3 打印流的应用场景 二、PrintStream详解2.1 基本概念2.2 构造函数2.3 核心方法2.4 使用示例 三、PrintWriter详解3.1 基本概念3.2 构造函数3.3 核心方法3.4 使用示例 四、PrintStream与PrintWriter的比…...

2025远离Deno和Fresh

原创作者&#xff1a;庄晓立&#xff08;LIIGO&#xff09; 原创时间&#xff1a;2025年6月6日 原创链接&#xff1a;https://blog.csdn.net/liigo/article/details/148479884 版权所有&#xff0c;转载请注明出处&#xff01; 相识 Deno&#xff0c;是Nodejs原开发者Ryan Da…...

Verilog编程技巧01——如何编写三段式状态机

前言 Verilog编程技巧系列文章将聚焦于介绍Verilog的各种编程范式或者说技巧&#xff0c;编程技巧和编程规范有部分重合&#xff0c;但并非完全一样。规范更注重编码的格式&#xff0c;像变量命名、缩进、注释风格等&#xff0c;而编程技巧则更偏重更直观易读、更便于维护、综合…...

电动螺丝刀-多实体拆图建模案例

多实体建模要注意下面两点&#xff1a; 多实体建模的合并结果一定要谨慎在实际工作中多实体建模是一个非常好的思路&#xff0c;先做产品的整体设计&#xff0c;再将个体零件导出去做局部细节设计 电动螺丝刀模型动图展示 爆炸视图动图展示 案例素材点击此处获取 建模步骤 1. …...

会计 - 合并1- 业务、控制、合并日

一、业务 1.1 业务的定义以及构成要素 业务,是指企业内部某些生产经营活动或资产的组合,该组合一般具有投入、加工处理过程和产出能力,能够独立计算其成本费用或所产生的收入。 (1)投入,指原材料、人工、必要的生产技术等无形资产以及构成产出能力的机器设备等其他长期资…...

DFT测试之TAP/SIB/TDR

TAP的作用 tap全称是test access port&#xff0c;是将jtag接口转为reset、sel、ce、ue、se、si、tck和so这一系列测试组件接口的模块。 jtag的接口主要是下面几个信号&#xff1a; 信号名称信号方向信号描述TCK&#xff08;测试时钟&#xff09;输入测试时钟&#xff0c;同…...

java面试场景题: 设计⼀个微博系统

微博系统设计指南&#xff1a;从理论到实践 系统设计考察的核心能力 系统设计面试模拟真实工作场景&#xff0c;候选人需与面试官协作解决模糊问题。关键在于沟通、分析和权衡能力&#xff0c;而非追求完美方案。面试官关注思考过程&#xff0c;而非最终答案。 常见误区与改…...

Linux常用命令学习手册

Linux常用命令学习手册https://download.csdn.net/download/2401_87690752/90953550 《Linux常用命令学习手册》提供了一份实用的Linux操作指南&#xff0c;主要收录了系统管理和文件操作等基础命令。内容涵盖了目录切换、文件查看、权限设置等核心功能&#xff0c;适合Linux初…...