Preface
Today, as AI applications become more and more widespread, optimizing deep learning models and deploying them for inference has become a necessary technology.
The OpenVINO toolkit (Open Visual Inference and Neural network Optimization) developed by Intel is such a powerful tool.
As an open source toolkit, OpenVINO provides developers with powerful deep learning model optimization and inference capabilities, supporting deployment across different Intel hardware platforms, including CPUs, integrated GPUs, Intel Movidius VPUs, and FPGAs.
The original intention of this toolkit is to implement a machine learning inference solution that can be deployed anywhere after coding. However, in the process of dealing with deep learning model inference, I gradually discovered that the PaddleSharp project I originally developed based on Baidu Paddlepaddle has better CPU inference OCR performance for the same model, and OpenVINO has better performance. So I started paying attention to OpenVINO and found that its C API did not have a suitable and high-quality package for the .NET world.
Some packages on the market may only meet the needs of specific projects and have insufficient functions; some may have perfect functions but the naming convention may not comply with the .NET community standards; some may have problems with error handling and performance, or may not be cross-platform. This contradicts the cross-platform nature of OpenVINO.
The .NET world desperately needs a higher quality OpenVINO package, and I feel like I have the ability to work on it. Therefore, I set a flag before this year’s holiday – I worked hard during the National Day and started the open source journey of OpenVINO.NET.
Address: https://github.com/sdcb/openvino.net
Package name | Version number | Introduction |
---|---|---|
Sdcb.OpenVINO | .NET PInvoke | |
Sdcb.OpenVINO.runtime.centos.7-x64 | CentOS 7 x64 | |
Sdcb.OpenVINO.runtime.debian.9-arm | Debian 9 ARM | |
Sdcb.OpenVINO.runtime.debian.9-arm64 | Debian 9 ARM64 | |
Sdcb.OpenVINO.runtime. rhel.8-x64 | RHEL 8 x64 | |
Sdcb.OpenVINO.runtime.ubuntu.18.04-x64 | Ubuntu 18.04 x64 | |
Sdcb.OpenVINO.runtime.ubuntu.20.04-x64 | Ubuntu 20.04 x64 | |
Sdcb.OpenVINO.runtime.ubuntu.22.04-x64 | Ubuntu 22.04 x64 | |
Sdcb.OpenVINO.runtime.win-x64 | Windows x64 |
-
Q: Why does
OpenVINO.NET
not directly referenceOpenCvSharp4
? -
A: I personally like
OpenCvSharp4
. The open source protocol is very friendly. However,OpenCvSharp4
does not officially support many platforms, and some people may preferEmgu.CV.
orImageSharp
, try not to kidnap it. -
Q: The C API has 158 function interfaces, 26 interface bodies, and detailed
XML
comments. How did you achieve it with high quality in a short time? -
A: I generated it automatically, I used the CppSharp project, CppSharp converts the header file contents of the C API into abstract syntax trees (AST), and then I converted these ASTs into well-annotated XML
C#
code. In fact, this is not the first time that I have applied CppSharp to an open source project. Interested friends can check out my Github Sdcb.OpenVINO.AutoGen project for implementation details.
For friends who want to know how to use it, I also wrote inference examples based on detection and classification of yolov8
, official face detection examples of OpenVINO
and my native design and Migrated PaddleOCR
project. In addition, I would also like to talk about the design ideas and future development direction of the project.
four examples
Face detection – based on the face-detection-0200 model provided by OpenVINO official website
In this example, I use the face-detection-0200
model provided by the OpenVINO official website. The official website provides an introduction page: https://docs.openvino.ai/2023.1/omz_models_model_face_detection_0200.html. The detailed sample code can be found from the mini-openvino-facedetection Github repository I created. When running, it will locate the face position in the camera and frame it. The rendering is as follows:
As shown in the picture, three objects were detected, the person, mobile phone and water cup in the picture, and the total time took about 30ms.
Object classification – classification model based on yolov8
The yolov8 model provides 1,000 different predefined categories. Like the above model, it needs to be downloaded and converted from the yolov8 official website. Friends who just want to try it out quickly can directly open another Github example I wrote: sdcb-openvino-yolov8-cls When running, the code will read an image and then try to guess which of the 1000 categories the image most resembles. In my code example, the input image is hen.jpg:
The output is as follows:
class id=hen, score=0.59 Preprocess time: 0.00ms infer time: 1.65ms Post process time: 0.49ms Total time: 2.14ms
using OpenCvSharp; using Sdcb.OpenVINO.PaddleOCR.Models.Online; using Sdcb.OpenVINO.PaddleOCR.Models; using Sdcb.OpenVINO.PaddleOCR; using System.Diagnostics; using System; FullOcrModel model = await OnlineFullModels.ChineseV3.DownloadAsync(); using Mat src = Cv2.ImDecode(await new HttpClient().GetByteArrayAsync("https://io.starworks.cc:88/paddlesharp/ocr/samples/xdr5450.webp"), ImreadModes.Color); using (PaddleOcrAll all = new(model) { AllowRotateDetection = true, Enable180Classification = true, }) { // Load local file by following code: // using (Mat src2 = Cv2.ImRead(@"C:\test.jpg")) Stopwatch sw = Stopwatch.StartNew(); PaddleOcrResult result = all.Run(src); Console.WriteLine($"elapsed={sw.ElapsedMilliseconds} ms"); Console.WriteLine("Detected all texts: \\ " + result.Text); foreach (PaddleOcrResultRegion region in result.Regions) { Console.WriteLine($"Text: {region.Text}, Score: {region.Score}, RectCenter: {region.Rect.Center}, RectSize: {region.Rect.Size}, Angle: {region.Rect. Angle}"); } }
The running effect is as follows:
elapsed=246 ms Detected all texts: High-speed 4X4160MHz data stream Double the number of streams in the 5GHz band twice as fast 3 AX5400 wireless specification router, The 5GHz band uses high-speed 4X4160MHz data stream, Compared with the mainstream AX3000 router on the market (2X2 data stream) The 5GHz band has twice the number of streams and twice the speed. ...
If you find this project useful or are currently using it, I welcome you to give me a star on my project homepage. This will be a huge encouragement to me! Your experience and stars are the motivation for me to continue working on .NET open source projects!
Reprinted from: .NET Sao operation
Link: cnblogs.com/sdflysha/p/20231015-sdcb-openvino-net.html
-EOF-
Technology group: Add editor WeChat dotnet999
Public account: Dotnet Lecture Hall