做网站多少cmstop

张小明 2026/1/19 20:41:05
做网站多少,cmstop,设计素材网站知乎,什么都能买到的网站一. 模型导出 二. 环境搭建 三. 代码程序 参考链接#xff1a;https://blog.csdn.net/qq_41375318/article/details/142747415 1. 模型导出 参考链接#xff1a;https://docs.ultralytics.com/zh/modes/export/#cli 将训练完成的YOLO模型导出成ONNX格式#xff0c;代码如…一. 模型导出二. 环境搭建三. 代码程序参考链接https://blog.csdn.net/qq_41375318/article/details/1427474151. 模型导出参考链接https://docs.ultralytics.com/zh/modes/export/#cli将训练完成的YOLO模型导出成ONNX格式代码如下from ultralytics import YOLO # Load a model model YOLO(yolo11n.pt) # load an official model model YOLO(path/to/best.pt) # load a custom-trained model # Export the model model.export(formatonnx)成功导出的onnx模型储存在yolo模型的同级目录下2. 环境搭建主要包括C#中的Nuget包下载其中需要的DLL包括4个Microsoft.ML.OnnxRuntimeMicrosoft.ML.OnnxRuntime.ManagedOpenCvSharp4OpenCvSharp4.runtime.win3. 代码程序3.1 检测结果类public class DetectionResult { public DetectionResult(int ClassId, string Class, Rect Rect, float Confidence) { this.ClassId ClassId; this.Confidence Confidence; this.Rect Rect; this.Class Class; } public string Class { get; set; } public int ClassId { get; set; } public float Confidence { get; set; } public Rect Rect { get; set; } }3.2 变量和Tanspose函数string fileFilter *.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png; string image_path ; string model_path; string classer_path; public string[] class_names; public int class_num; DateTime dt1 DateTime.Now; DateTime dt2 DateTime.Now; int input_height; int input_width; float ratio_height; float ratio_width; InferenceSession onnx_session; int box_num; float conf_threshold; float nms_threshold; public unsafe float[] Transpose(float[] tensorData, int rows, int cols) { float[] transposedTensorData new float[tensorData.Length]; fixed (float* pTensorData tensorData) { fixed (float* pTransposedData transposedTensorData) { for (int i 0; i rows; i) { for (int j 0; j cols; j) { int index i * cols j; int transposedIndex j * rows i; pTransposedData[transposedIndex] pTensorData[index]; } } } } return transposedTensorData; }3.2 加载模型与label.txtprivate void Form1_Load(object sender, EventArgs e) { model_path ...\...\model\yolo11n.onnx; //创建输出会话用于输出模型读取信息 SessionOptions options new SessionOptions(); options.LogSeverityLevel OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO; options.AppendExecutionProvider_CPU(0);// 设置为CPU上运行 // 创建推理模型类读取模型文件 onnx_session new InferenceSession(model_path, options);//model_path 为onnx模型文件的路径 input_height 640; input_width 640; box_num 8400; conf_threshold 0.25f; nms_threshold 0.5f; classer_path ...\...\model\label.txt; class_names File.ReadAllLines(classer_path, Encoding.UTF8); class_num class_names.Length; // 图片路径 image_path ...\...\image1.jpg; pictureBox1.Image new Bitmap(image_path); }3.3 开始检测推理private void button2_Click(object sender, EventArgs e) { if (image_path ) { return; } button2.Enabled false; pictureBox2.Image null; textBox1.Text ; Application.DoEvents(); Mat image new Mat(image_path); //图片缩放 int height image.Rows; int width image.Cols; Mat temp_image image.Clone(); if (height input_height || width input_width) { float scale Math.Min((float)input_height / height, (float)input_width / width); OpenCvSharp.Size new_size new OpenCvSharp.Size((int)(width * scale), (int)(height * scale)); Cv2.Resize(image, temp_image, new_size); } ratio_height (float)height / temp_image.Rows; ratio_width (float)width / temp_image.Cols; Mat input_img new Mat(); Cv2.CopyMakeBorder(temp_image, input_img, 0, input_height - temp_image.Rows, 0, input_width - temp_image.Cols, BorderTypes.Constant, 0); //Cv2.ImShow(input_img, input_img); //输入Tensor Tensorfloat input_tensor new DenseTensorfloat(new[] { 1, 3, 640, 640 }); for (int y 0; y input_img.Height; y) { for (int x 0; x input_img.Width; x) { input_tensor[0, 0, y, x] input_img.AtVec3b(y, x)[0] / 255f; input_tensor[0, 1, y, x] input_img.AtVec3b(y, x)[1] / 255f; input_tensor[0, 2, y, x] input_img.AtVec3b(y, x)[2] / 255f; } } ListNamedOnnxValue input_container new ListNamedOnnxValue { NamedOnnxValue.CreateFromTensor(images, input_tensor) }; //推理 dt1 DateTime.Now; var ort_outputs onnx_session.Run(input_container).ToArray(); dt2 DateTime.Now; float[] data Transpose(ort_outputs[0].AsTensorfloat().ToArray(), 4 class_num, box_num); float[] confidenceInfo new float[class_num]; float[] rectData new float[4]; ListDetectionResult detResults new ListDetectionResult(); for (int i 0; i box_num; i) { Array.Copy(data, i * (class_num 4), rectData, 0, 4); Array.Copy(data, i * (class_num 4) 4, confidenceInfo, 0, class_num); float score confidenceInfo.Max(); // 获取最大值 int maxIndex Array.IndexOf(confidenceInfo, score); // 获取最大值的位置 int _centerX (int)(rectData[0] * ratio_width); int _centerY (int)(rectData[1] * ratio_height); int _width (int)(rectData[2] * ratio_width); int _height (int)(rectData[3] * ratio_height); detResults.Add(new DetectionResult( maxIndex, class_names[maxIndex], new Rect(_centerX - _width / 2, _centerY - _height / 2, _width, _height), score)); } //NMS CvDnn.NMSBoxes(detResults.Select(x x.Rect), detResults.Select(x x.Confidence), conf_threshold, nms_threshold, out int[] indices); detResults detResults.Where((x, index) indices.Contains(index)).ToList(); //绘制结果 Mat result_image image.Clone(); foreach (DetectionResult r in detResults) { Cv2.PutText(result_image, ${r.Class}:{r.Confidence:P0}, new OpenCvSharp.Point(r.Rect.TopLeft.X, r.Rect.TopLeft.Y - 10), HersheyFonts.HersheySimplex, 1, Scalar.Red, 2); Cv2.Rectangle(result_image, r.Rect, Scalar.Red, thickness: 2); } pictureBox2.Image new Bitmap(result_image.ToMemoryStream()); textBox1.Text 推理耗时: (dt2 - dt1).TotalMilliseconds ms; button2.Enabled true; }注意设置picture1和picture2的SizeMode属性为Zoom
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

青岛网站制作永诚wordpress lang

你是否曾在Vue3项目中集成地图功能时,面对复杂的API文档和繁琐的初始化步骤感到头疼?当产品经理要求添加实时位置追踪或热力图展示时,你是否在地图API的回调地狱中挣扎?今天,让我们一起探索vue3-google-map组件化方案&…

张小明 2025/12/26 4:24:00 网站建设

丰都网站建设哪家好建设银行临夏分行网站

ApkShellExt2:Windows资源管理器的APK文件智能管理革命 【免费下载链接】apkshellext Show app icons in windows explorer 项目地址: https://gitcode.com/gh_mirrors/ap/apkshellext 还在为Windows中一堆相同的压缩包图标而烦恼吗?ApkShellExt…

张小明 2026/1/1 18:46:18 网站建设

网站怎么被黑自已做的网站怎么做域名解析

一、设计背景与核心需求 现代生活中,饮食热量与营养摄入的精准管理对健康管理至关重要,传统厨房秤仅能测量重量,无法关联食物营养信息,难以满足健康饮食需求。基于单片机的饮食健康秤,融合称重功能与营养数据查询&…

张小明 2026/1/10 18:14:19 网站建设

广州建设官方网站免费做彩页网站

JVC DSP调音软件终极指南:多型号版本V1.09快速上手 【免费下载链接】JVCDSP功放调音软件多型号版本V1.09 JVC DSP功放调音软件多型号版本V1.09专为JVC用户设计,提供便捷高效的调音体验。支持KS-DR420P、KS-DR480P、KS-AX810P、KS-AX1220P及KS-AX1012HP等…

张小明 2025/12/25 22:44:58 网站建设

搜狗站长工具平台德州市网站建设

本文详细解析了LangGraph框架中的Supervisor(代理主管)机制,通过微软Magentic-One系统引出多智能体协作架构。文章介绍了Supervisor"分工明确中央协调动态路由"的核心思想,提供了完整代码实现和数据库分析案例&#xff…

张小明 2026/1/6 19:08:11 网站建设

专做机械零配件的网站品牌网站模板

CPUDoc性能优化全攻略:解锁CPU潜能的系统级解决方案 【免费下载链接】CPUDoc 项目地址: https://gitcode.com/gh_mirrors/cp/CPUDoc 还在为电脑响应迟缓、多任务处理卡顿而困扰?想要在不升级硬件的前提下获得显著的性能提升?CPUDoc作…

张小明 2025/12/26 6:23:08 网站建设