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

帮人做网站赚钱吗即时聊天wordpress手机app

帮人做网站赚钱吗,即时聊天wordpress手机app,网络广告的特点有哪些?,《设计》在线观看在 MacOS 上使用 OpenVINO™ C# API 部署 Yolov5 #xff08;下篇#xff09; 项目介绍 YOLOv5 是革命性的 单阶段对象检测模型的第五次迭代#xff0c;旨在实时提供高速、高精度的结果#xff0c;是世界上最受欢迎的视觉人工智能模型#xff0c;代表了Ult… 在 MacOS 上使用 OpenVINO™ C# API 部署 Yolov5 下篇 项目介绍 YOLOv5 是革命性的 单阶段对象检测模型的第五次迭代旨在实时提供高速、高精度的结果是世界上最受欢迎的视觉人工智能模型代表了Ultralytics对未来视觉人工智能方法的开源研究融合了数千小时研发中积累的经验教训和最佳实践。同时官方发布的模型已经支持 OpenVINO™ 部署工具加速模型推理因此在该项目中我们将结合之前开发的 OpenVINO™ C# API 部署 YOLOv5 DET 模型实现物体对象检测。 项目链接为 https://github.com/guojin-yan/OpenVINO-CSharp-API项目源码链接为 https://github.com/guojin-yan/OpenVINO-CSharp-API-Samples/tree/master/model_samples/yolov5/yolov5_det_opencvsharp https://github.com/guojin-yan/OpenVINO-CSharp-API-Samples/tree/master/model_samples/yolov5/yolov5_det_emgucv文章目录 3. Yolov5 DET 项目配置(OpenCvSharp版)3.1 项目创建3.2 添加项目依赖3.3 定义预测方法(1) 使用常规方式部署模型(2) 使用模型结构处理处理数据(3) 使用 OpenVINO™ C# API 封装的接口 3.4 预测方法调用 4. Yolov5 DET 项目配置(Emgu.CV 版)4.1 添加项目依赖4.2 定义预测方法 5. 项目运行与演示5.1 项目编译 6. 总结 3. Yolov5 DET 项目配置(OpenCvSharp版) 3.1 项目创建 如果开发者第一次在MacOS系统上使用C#编程语言可以参考《在MacOS系统上配置OpenVINO™ C# API》文章进行配置。 首先使用dotnet创建一个测试项目在终端中输入一下指令 dotnet new console --framework net6.0 --use-program-main -o yolov5-det 3.2 添加项目依赖 MacOS系统目前主要分为两类一类是使用intel处理器的X64位的系统一类是使用M系列芯片的arm64位系统目前OpenVINO官方针对这两种系统都提供了编译后的系统所以目前OpenVINO.CSharp.API针对这两种系统都提供了支持。 此处以M系列处理器的MacOS平台为例安装项目依赖首先是安装OpenVINO™ C# API项目依赖在命令行中输入以下指令即可 dotnet add package OpenVINO.CSharp.API dotnet add package OpenVINO.runtime.macos-arm64 dotnet add package OpenVINO.CSharp.API.Extensions dotnet add package OpenVINO.CSharp.API.Extensions.OpenCvSharp关于在MacOS上搭建 OpenVINO™ C# API 开发环境请参考以下文章 在MacOS上搭建OpenVINO™C#开发环境 接下来安装使用到的图像处理库 OpenCvSharp在命令行中输入以下指令即可 dotnet add package OpenCvSharp4 dotnet add package OpenCvSharp4.Extensions dotnet add package OpenCvSharp4.runtime.osx_arm64 --prerelease关于在MacOS上搭建 OpenCvSharp 开发环境请参考以下文章 【OpenCV】在MacOS上使用OpenCvSharp 添加完成项目依赖后项目的配置文件如下所示 Project SdkMicrosoft.NET.SdkPropertyGroupOutputTypeExe/OutputTypeTargetFrameworknet6.0/TargetFrameworkRootNamespaceyolov5_det/RootNamespaceImplicitUsingsenable/ImplicitUsingsNullableenable/Nullable/PropertyGroupItemGroupPackageReference IncludeOpenCvSharp4 Version4.9.0.20240103 /PackageReference IncludeOpenCvSharp4.Extensions Version4.9.0.20240103 /PackageReference IncludeOpenCvSharp4.runtime.osx_arm64 Version4.8.1-rc /PackageReference IncludeOpenVINO.CSharp.API Version2023.2.0.4 /PackageReference IncludeOpenVINO.CSharp.API.Extensions Version1.0.1 /PackageReference IncludeOpenVINO.CSharp.API.Extensions.OpenCvSharp Version1.0.4 /PackageReference IncludeOpenVINO.runtime.macos-arm64 Version2023.3.0.1 //ItemGroup/Project3.3 定义预测方法 (1) 使用常规方式部署模型 Yolov5 属于比较经典单阶段目标检测模型其模型输入为640*640的归一化处理后的图像数据输出为未进行NMS的推理结果因此在获取推理结果后需要进行NMS其实现代码如下所示 static void yolov5_det(string model_path, string image_path, string device) {// -------- Step 1. Initialize OpenVINO Runtime Core --------Core core new Core();// -------- Step 2. Read inference model --------Model model core.read_model(model_path);OvExtensions.printf_model_info(model);// -------- Step 3. Loading a model to the device --------start DateTime.Now;CompiledModel compiled_model core.compile_model(model, device);// -------- Step 4. Create an infer request --------InferRequest infer_request compiled_model.create_infer_request();// -------- Step 5. Process input images --------Mat image new Mat(image_path); // Read image by opencvsharpint max_image_length image.Cols image.Rows ? image.Cols : image.Rows;Mat max_image Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3);Rect roi new Rect(0, 0, image.Cols, image.Rows);image.CopyTo(new Mat(max_image, roi));float factor (float)(max_image_length / 640.0);// -------- Step 6. Set up input data --------Tensor input_tensor infer_request.get_input_tensor();Shape input_shape input_tensor.get_shape();Mat input_mat CvDnn.BlobFromImage(max_image, 1.0 / 255.0, new OpenCvSharp.Size(input_shape[2], input_shape[3]), 0, true, false);float[] input_data new float[input_shape[1] * input_shape[2] * input_shape[3]];Marshal.Copy(input_mat.Ptr(0), input_data, 0, input_data.Length);input_tensor.set_datafloat(input_data);// -------- Step 7. Do inference synchronously --------infer_request.infer();// -------- Step 8. Get infer result data --------Tensor output_tensor infer_request.get_output_tensor();int output_length (int)output_tensor.get_size();float[] output_data output_tensor.get_datafloat(output_length);// -------- Step 9. Process reault --------Mat result_data new Mat(25200, 85, MatType.CV_32F, output_data);// Storage results listListRect position_boxes new ListRect();Listint class_ids new Listint();Listfloat confidences new Listfloat();// Preprocessing output resultsfor (int i 0; i result_data.Rows; i){float confidence result_data.Atfloat(i, 4);if (confidence 0.5){continue;}Mat classes_scores new Mat(result_data, new Rect(5, i, 80, 1));OpenCvSharp.Point max_classId_point, min_classId_point;double max_score, min_score;// Obtain the maximum value and its position in a set of dataCv2.MinMaxLoc(classes_scores, out min_score, out max_score,out min_classId_point, out max_classId_point);// Confidence level between 0 ~ 1// Obtain identification box informationif (max_score 0.25){float cx result_data.Atfloat(i, 0);float cy result_data.Atfloat(i, 1);float ow result_data.Atfloat(i, 2);float oh result_data.Atfloat(i, 3);int x (int)((cx - 0.5 * ow) * factor);int y (int)((cy - 0.5 * oh) * factor);int width (int)(ow * factor);int height (int)(oh * factor);Rect box new Rect();box.X x;box.Y y;box.Width width;box.Height height;position_boxes.Add(box);class_ids.Add(max_classId_point.X);confidences.Add((float)confidence);}}// NMS non maximum suppressionint[] indexes new int[position_boxes.Count];CvDnn.NMSBoxes(position_boxes, confidences, 0.5f, 0.5f, out indexes);for (int i 0; i indexes.Length; i){int index indexes[i];Cv2.Rectangle(image, position_boxes[index], new Scalar(0, 0, 255), 2, LineTypes.Link8);Cv2.Rectangle(image, new OpenCvSharp.Point(position_boxes[index].TopLeft.X, position_boxes[index].TopLeft.Y 30),new OpenCvSharp.Point(position_boxes[index].BottomRight.X, position_boxes[index].TopLeft.Y), new Scalar(0, 255, 255), -1);Cv2.PutText(image, class_ids[index] - confidences[index].ToString(0.00),new OpenCvSharp.Point(position_boxes[index].X, position_boxes[index].Y 25),HersheyFonts.HersheySimplex, 0.8, new Scalar(0, 0, 0), 2);}string output_path Path.Combine(Path.GetDirectoryName(Path.GetFullPath(image_path)),Path.GetFileNameWithoutExtension(image_path) _result.jpg);Cv2.ImWrite(output_path, image);Slog.INFO(The result save to output_path);Cv2.ImShow(Result, image);Cv2.WaitKey(0); }(2) 使用模型结构处理处理数据 目前 OpenVINO™ 已经支持在模型结构中增加数据的前后处理流程并且在 OpenVINO™ C# API 中也已经实现了该功能接口所以在此处演示了如何将模型输入数据处理流程封装到模型中通过 OpenVINO™ 进行数据处理的加速处理如下面代码所示: static void yolov5_det_with_process(string model_path, string image_path, string device) {······// -------- Step 2. Read inference model --------start DateTime.Now;Model model core.read_model(model_path);OvExtensions.printf_model_info(model);PrePostProcessor processor new PrePostProcessor(model);Tensor input_tensor_pro new Tensor(new OvType(ElementType.U8), new Shape(1, 640, 640, 3));InputInfo input_info processor.input(0);InputTensorInfo input_tensor_info input_info.tensor();input_tensor_info.set_from(input_tensor_pro).set_layout(new Layout(NHWC)).set_color_format(ColorFormat.BGR);PreProcessSteps process_steps input_info.preprocess();process_steps.convert_color(ColorFormat.RGB).resize(ResizeAlgorithm.RESIZE_LINEAR).convert_element_type(new OvType(ElementType.F32)).scale(255.0f).convert_layout(new Layout(NCHW));Model new_model processor.build();// -------- Step 3. Loading a model to the device --------CompiledModel compiled_model core.compile_model(new_model, device);// -------- Step 4. Create an infer request --------InferRequest infer_request compiled_model.create_infer_request();// -------- Step 5. Process input images --------Mat image new Mat(image_path); // Read image by opencvsharpint max_image_length image.Cols image.Rows ? image.Cols : image.Rows;Mat max_image Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3);Rect roi new Rect(0, 0, image.Cols, image.Rows);image.CopyTo(new Mat(max_image, roi));Cv2.Resize(max_image, max_image, new OpenCvSharp.Size(640, 640));float factor (float)(max_image_length / 640.0);// -------- Step 6. Set up input data --------Tensor input_tensor infer_request.get_input_tensor();Shape input_shape input_tensor.get_shape();byte[] input_data new byte[input_shape[1] * input_shape[2] * input_shape[3]];Marshal.Copy(max_image.Ptr(0), input_data, 0, input_data.Length);IntPtr destination input_tensor.data();Marshal.Copy(input_data, 0, destination, input_data.Length);// -------- Step 7. Do inference synchronously --------······ }由于目前还没有完全实现所有的 OpenVINO™ 的预处理接口因此只能实现部分预处理过程封装到模型中此处主要是做了以下处理 数据类型转换byte-float数据维度转换NHWC-NCHW图像色彩空间转换BGR-RGB数据归一化处理[0,1]-[0,255] 因此将一些数据处理流程封装到模型中后在进行模型推理时只需要将读取到的图片数据Resize为640*640后就可以直接将数据加载到模型即可。 (3) 使用 OpenVINO™ C# API 封装的接口 YOLOv5 是当前工业领域十分流行的目标检测模型因此在封装 OpenVINO™ C# API 时提供了快速部署 Yolov5 模型的接口实现代码如下所示 static void yolov5_det_using_extensions(string model_path, string image_path, string device) {Yolov5DetConfig config new Yolov5DetConfig();config.set_model(model_path);Yolov5Det yolov8 new Yolov5Det(config);Mat image Cv2.ImRead(image_path);DetResult result yolov8.predict(image);Mat result_im Visualize.draw_det_result(result, image);Cv2.ImShow(Result, result_im);Cv2.WaitKey(0); }3.4 预测方法调用 定义好上述方法后便可以直接在主函数中调用该方法只需要在主函数中增加以下代码即可 yolov5_det(yolov5s.xml, test_image.png, AUTO); yolov5_det_with_process(yolov5s.xml, test_image.png, AUTO); yolov5_det_using_extensions(yolov5s.xml, test_image.png, AUTO);如果开发者自己没有进行模型下载与转换又同时想快速体验该项目我此处提供了在线的转换后的模型以及带预测图片开发者可以直接在主函数中增加以下代码便可以直接自动下载模型以及推理数据并调用推理方法实现程序直接运行。 static void Main(string[] args) {string model_path ;string image_path ;string device AUTO;if (args.Length 0){if (!Directory.Exists(./model)){Directory.CreateDirectory(./model);}if (!File.Exists(./model/yolov5s.bin) !File.Exists(./model/yolov5s.bin)){if (!File.Exists(./model/yolov5s.tar)){_ Download.download_file_async(https://github.com/guojin-yan/OpenVINO-CSharp-API-Samples/releases/download/Model/yolov5s.tar,./model/yolov5s.tar).Result;}Download.unzip(./model/yolov585s.tar, ./model/);}if (!File.Exists(./model/test_image.jpg)){_ Download.download_file_async(https://github.com/guojin-yan/OpenVINO-CSharp-API-Samples/releases/download/Image/test_det_02.jpg,./model/test_image.jpg).Result;}model_path ./model/yolov5s.xml;image_path ./model/test_image.jpg;}else if (args.Length 2){model_path args[0];image_path args[1];device args[2];}else{Console.WriteLine(Please enter the correct command parameters, for example:);Console.WriteLine( 1. dotnet run);Console.WriteLine( 2. dotnet run model path image path device name);}// -------- Get OpenVINO runtime version --------OpenVinoSharp.Version version Ov.get_openvino_version();Slog.INFO(---- OpenVINO INFO----);Slog.INFO(Description : version.description);Slog.INFO(Build number: version.buildNumber);Slog.INFO(Predict model files: model_path);Slog.INFO(Predict image files: image_path);Slog.INFO(Inference device: device);Slog.INFO(Start yolov8 model inference.);yolov5_det(model_path, image_path, device);//yolov5_det_with_process(model_path, image_path, device);//yolov5_det_using_extensions(model_path, image_path, device); }为了减少文章篇幅所以此处只提供了有差异的代码如果想获取完整代码请访问GitHub代码仓库获取项目源码链接为 https://github.com/guojin-yan/OpenVINO-CSharp-API-Samples/tree/master/model_samples/yolov5/yolov5_det_opencvsharp4. Yolov5 DET 项目配置(Emgu.CV 版) 同样地为了满足Emgu.CV开发者的需求此处同样地提供了Emgu.CV版本的Yolov5的模型部署代码以及使用流程此处为了简化文章内容对于和上文重复的步骤不在进行展开讲述。 4.1 添加项目依赖 首先是安装OpenVINO™ C# API项目依赖在命令行中输入以下指令即可 dotnet add package OpenVINO.CSharp.API dotnet add package OpenVINO.runtime.macos-arm64 dotnet add package OpenVINO.CSharp.API.Extensions dotnet add package OpenVINO.CSharp.API.Extensions.EmguCV接下来安装使用到的图像处理库 Emgu.CV在命令行中输入以下指令即可 dotnet add package Emgu.CV dotnet add package Emgu.CV.runtime.mini.macos关于在MacOS上搭建 OpenCvSharp 开发环境请参考以下文章 【OpenCV】在MacOS上使用Emgu.CV 添加完成项目依赖后项目的配置文件如下所示 Project SdkMicrosoft.NET.SdkPropertyGroupOutputTypeExe/OutputTypeTargetFrameworknet6.0/TargetFrameworkRootNamespaceyolov5_det/RootNamespaceImplicitUsingsenable/ImplicitUsingsNullableenable/Nullable/PropertyGroupItemGroupPackageReference IncludeEmgu.CV Version4.8.1.5350 /PackageReference IncludeEmgu.CV.runtime.mini.macos Version4.8.1.5350 /PackageReference IncludeOpenVINO.CSharp.API Version2023.2.0.4 /PackageReference IncludeOpenVINO.CSharp.API.Extensions Version1.0.1 /PackageReference IncludeOpenVINO.CSharp.API.Extensions.EmguCV Version1.0.4.1 /PackageReference IncludeOpenVINO.runtime.macos-arm64 Version2023.3.0.1 //ItemGroup/Project4.2 定义预测方法 模型部署流程与上一节中使用OpenCvSharp的基本一致主要是替换了图像处理的工具同时提供了如上一节中所展示的三种部署方式。此处为了减少文章篇幅此处不在展示详细的部署代码如果想获取相关代码请访问项目GitHub下载所有的测试代码项目链接为 https://github.com/guojin-yan/OpenVINO-CSharp-API-Samples/tree/master/model_samples/yolov5/yolov5_det_emgucv5. 项目运行与演示 5.1 项目编译 接下来输入项目编译指令进行项目编译输入以下指令即可 dotnet build程序编译后输出为 ### 5.2 项目文件运行 接下来运行编译后的程序文件在CMD中输入以下指令运行编译后的项目文件 dotnet run --no-build运行后项目输出为 6. 总结 在该项目中我们结合之前开发的 OpenVINO C# API 项目部署YOLOv5模型成功实现了对象目标检测并且根据不同开发者的使用习惯同时提供了OpenCvSharp以及Emgu.CV两种版本供各位开发者使用。最后如果各位开发者在使用中有任何问题欢迎大家与我联系。
http://www.w-s-a.com/news/258070/

相关文章:

  • 专业门户网站的规划与建设网络培训
  • 东莞汽车总站停止营业crm管理系统在线使用
  • 深圳网站建设公司哪个网络优化是做什么的
  • 大连地区做网站自己怎么做电影网站
  • 成都APP,微网站开发手机要访问国外网站如何做
  • 网站app建设用discuz做的手机网站
  • vs 2008网站做安装包公众号登录超时
  • 银川做网站推广wordpress dux会员中心
  • 双辽做网站wordpress怎么写html代码
  • 建站公司哪家好 知道万维科技西安都有哪些公司
  • 设计网站官网入口佛山 品牌设计
  • 专用网站建设wordpress mega
  • 网站建设与优化推广方案内容网站整站下载带数据库后台的方法
  • 做网站PAAS系统外链是什么意思
  • 网页设计专业设计课程googleseo排名公司
  • 网站百度百科那些免费网站可以做国外贸易
  • 做视频的网站有哪些南京计算机培训机构哪个最好
  • ppt做视频 模板下载网站商业街网站建设方案
  • 佛山网站定制开发星光影视园网站建设案例
  • wordpress子站点商务网页设计与制作微课版答案
  • 山东省住房城乡和建设厅网站软件开发主要几个步骤
  • 可以接项目做的网站网站源码php
  • 杭州广众建设工程有限公司网站网页游戏人气排行榜
  • 上海网站开发建设最简单的网站代码
  • 东莞做网站建设免费网站建设案例
  • 莱州建设局网站wordpress的主题下载地址
  • 二级网站域名长沙企业关键词优化服务质量
  • 在家有电脑怎么做网站wordpress 入门主题
  • 什邡建设局网站sem推广是什么意思
  • 西安分类信息网站网站敏感关键词