Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSharp API] Add and init modules.csharp_api project, provide methods for using the CSharp API #733

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
249dfa9
Add and init modules.csharp_api project, provide methods for using th…
guojin-yan Sep 25, 2023
b5b7ba1
Modify the Chinese language in the source code and add exception hand…
guojin-yan Oct 7, 2023
89aecec
Merge branch 'master' into master
guojin-yan Oct 9, 2023
1440449
Modify Dimension. is_ dynamic() judgment method,
guojin-yan Oct 19, 2023
b97e71e
Optimize and improve the implementation of PartialShape class, and co…
guojin-yan Oct 19, 2023
ae5ba76
Update code.
guojin-yan Oct 19, 2023
cabc899
Merge branch 'master' of github.com:guojin-yan/openvino_contrib
guojin-yan Oct 19, 2023
732887c
Simplify the code, remove OpenCvSharp dependencies from the code, and…
guojin-yan Oct 19, 2023
6af235c
Modify formatting issues in the code.
guojin-yan Oct 24, 2023
35126cc
Update READM.md and add a new version of NuGet Package
guojin-yan Oct 24, 2023
f1cea9f
Add the IDisposable interface to the Input class.
guojin-yan Oct 24, 2023
2b1c7e2
Clean up references to OpenCvSharp in the code and reduce its relianc…
guojin-yan Oct 24, 2023
479db9c
Modify the new NuGet Package generation settings.
guojin-yan Oct 24, 2023
4ffc695
Update README.md.
guojin-yan Oct 24, 2023
9cae894
Modify the details in the code.
guojin-yan Oct 24, 2023
a5f7a52
Update README.md.
guojin-yan Oct 24, 2023
c0e1878
Modify the PackageProjectUrl address.
guojin-yan Oct 24, 2023
cc78cea
[Csharp API Extension] Add missing files & Configure CI .
guojin-yan Oct 25, 2023
7111f13
Modify the get_partial_shape() method of PartialShape class.
guojin-yan Nov 2, 2023
13d4463
Modify the program method entry point name in ov_partial_shape.
guojin-yan Nov 2, 2023
5df5e57
Modify the reshape(Dictionary<string, PartialShape> partial_shapes) m…
guojin-yan Nov 2, 2023
34824cc
Error modifying comments
guojin-yan Nov 3, 2023
5118ed2
Update nuget package description.
guojin-yan Nov 6, 2023
e44b580
Add C API ov_get_last_err_msg(), Set specific information for except…
guojin-yan Nov 24, 2023
78024a4
Fix error and return text parsing error.
guojin-yan Nov 27, 2023
3ad5030
Add and fix set_property()、get_property() methods.
guojin-yan Nov 30, 2023
38e01a6
Add content_from_file(string file) method.
guojin-yan Jan 18, 2024
d459f16
Fix struct ProfilingInfo error.
guojin-yan Jan 18, 2024
e55a7a1
Fix method error.
guojin-yan Jan 18, 2024
a6e3a0c
Add default constructor.
guojin-yan Jan 18, 2024
eb84f0b
Add parameter constructor.
guojin-yan Jan 18, 2024
1a16407
Add set_tensor(Input port, Tensor tensor) method.
guojin-yan Jan 18, 2024
5629694
Add exception handling.
guojin-yan Jan 18, 2024
e2c82a5
Add default param.
guojin-yan Jan 18, 2024
7fd8eab
Add an indefinite parameter construction method.
guojin-yan Jan 18, 2024
b40f647
Fix method error.
guojin-yan Jan 18, 2024
b242267
Add indefinite parameter method interface.
guojin-yan Jan 18, 2024
e0a8650
Fix error.
guojin-yan Jan 18, 2024
1134900
Fix interface name error.
guojin-yan Jan 18, 2024
545b5d2
Fix error.
guojin-yan Jan 18, 2024
d8cd173
Add unit tests.
guojin-yan Jan 18, 2024
0384be9
Update readme.
guojin-yan Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions modules/csharp_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# OpenVINO™ C# API

<img src="https://img.shields.io/badge/Framework-.NET6.0%2C%20.NET48-pink.svg">

[简体中文](README_cn.md) | English

## 📚 What is OpenVINO™ C# API ?

[OpenVINO™](www.openvino.ai) is an open-source toolkit for optimizing and deploying AI inference.

- Boost deep learning performance in computer vision, automatic speech recognition, natural language processing and other common tasks
- Use models trained with popular frameworks like TensorFlow, PyTorch and more
- Reduce resource demands and efficiently deploy on a range of Intel® platforms from edge to cloud

&emsp; This project is mainly based on OpenVINO ™ OpenVINO launched by tool kit ™ C # API, aimed at driving OpenVINO ™ Application on the C # platform.

&emsp; OpenVINO ™ The C # API is based on OpenVINO ™ C API development, supported platforms and OpenVINO ™ Consistent, please refer to OpenVINO for specific information ™。

## <img title="NuGet" src="https://s2.loli.net/2023/01/26/ks9BMwXaHqQnKZP.png" alt="" width="40"> NuGet Package

&emsp; C # supports NuGet Package installation and one-stop installation on platforms such as Linux and Window. Therefore, in order to facilitate more users, a NuGet Package for use on the Window platform has been released for the convenience of everyone.

| Package | Description | Link |
| ----------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| **OpenVINO.CSharp.win** | OpenVINO™ C# API core libraries,comes with a complete OpenVINO 2023.0 dependency library | [![NuGet Gallery ](https://badge.fury.io/nu/OpenVINO.CSharp.win.svg)](https://www.nuget.org/packages/OpenVINO.CSharp.win/) |

## ⚙ How to install OpenVINO™ C# API?

The following article provides installation methods for OpenVINO™ C# API on different platforms, which can be installed according to your own platform.

- [Windows](docs/en/windows_install.md)

- [Linux](docs/en/linux_install.md)

## 🏷How to use OpenVINO™ C# API?

- **Quick start**
- [Deploying the Yolov8 full series model using OpenVINO™ C# API](demos/yolov8/README.md)

- **Simple usage**

If you don't know how to use it, simply understand the usage method through the following code.

```c#
namespace test
{
internal class Program
{
static void Main(string[] args)
{
Core core = new Core();
Model model = core.read_model("./model.xml");
CompiledModel compiled_model = core.compiled_model(model, "AUTO");
InferRequest infer_request = compiled_model.create_infer_request();
Tensor input_tensor = infer_request.get_tensor("images");
infer_request.infer();
Tensor output_tensor = infer_request.get_tensor("output0");
core.free();
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
```

The classes and objects encapsulated in the project, such as Core, Model, Tensor, etc., are implemented by calling the C API interface and have unmanaged resources. They need to be handled by calling the **dispose() ** method, otherwise memory leakage may occur.
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved

## 🗂 API Reference

If you want to learn more information, you can refer to: [OpenVINO™ C# API API Documented](https://guojin-yan.github.io/OpenVINO-CSharp-API.docs/)
73 changes: 73 additions & 0 deletions modules/csharp_api/README_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# OpenVINO™ C# API

<img src="https://img.shields.io/badge/Framework-.NET6.0%2C%20.NET48-pink.svg">


简体中文| [English](README.md)

## 📚 简介

[OpenVINO™ ](www.openvino.ai)是一个用于优化和部署 AI 推理的开源工具包。

- 提升深度学习在计算机视觉、自动语音识别、自然语言处理和其他常见任务中的性能
- 使用流行框架(如TensorFlow,PyTorch等)训练的模型
- 减少资源需求,并在从边缘到云的一系列英特尔®平台上高效部署

&emsp; 该项目主要是基于OpenVINO™工具套件推出的 OpenVINO™ C# API,旨在推动 OpenVINO™ 在C#平台的应用。

&emsp; OpenVINO™ C# API 由于是基于 OpenVINO™ C API 开发,所支持的平台与OpenVINO™ 一致,具体信息可以参考 OpenVINO™。

## <img title="NuGet" src="https://s2.loli.net/2023/01/26/ks9BMwXaHqQnKZP.png" alt="" width="40"> NuGet Package

C# 支持 NuGet Package 方式安装程序包,在Linux、Window 等平台支持一站式安装使用,因此为了方便更多用户使用,目前发行了 Window 平台下使用的 NuGet Package ,方便大家使用。

| Package | Description | Link |
| ----------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| **OpenVINO.CSharp.win** | OpenVINO™ C# API core libraries,附带完整的OpenVINO 2023.1依赖库 | [![NuGet Gallery ](https://badge.fury.io/nu/OpenVINO.CSharp.win.svg)](https://www.nuget.org/packages/OpenVINO.CSharp.win/) |

## ⚙ 如何安装

以下文章提供了OpenVINO™ C# API在不同平台的安装方法,可以根据自己使用平台进行安装。

- [Windows](docs/cn/windows_install.md)

- [Linux](docs/cn/linux_install.md)

## 🏷开始使用

- **快速体验**

[使用OpenVINO™ C# API部署Yolov8全系列模型](demos/yolov8/README_cn.md)

- **使用方法**

如果你不知道如何使用,通过下面代码简单了解使用方法。

```c#
namespace test
{
internal class Program
{
static void Main(string[] args)
{
Core core = new Core(); // 初始化 Core 核心
Model model = core.read_model("./model.xml"); // 读取模型文件
CompiledModel compiled_model = core.compiled_model(model, "AUTO"); // 将模型加载到设备
InferRequest infer_request = compiled_model.create_infer_request(); // 创建推理通道
Tensor input_tensor = infer_request.get_tensor("images"); // 获取输入节点Tensor
infer_request.infer(); // 模型推理
Tensor output_tensor = infer_request.get_tensor("output0"); // 获取输出节点Tensor
core.free(); // 清理 Core 非托管内存
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
```

项目中所封装的类、对象例如Core、Model、Tensor等,通过调用 C api 接口实现,具有非托管资源,需要调用**dispose()**方法处理,否则就会出现内存泄漏。

## 🗂 API 文档

如果想了解更多信息,可以参阅:[OpenVINO™ C# API API Documented](https://guojin-yan.github.io/OpenVINO-CSharp-API.docs/)



67 changes: 67 additions & 0 deletions modules/csharp_api/csharp/CSharpAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;net48</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>OpenVINO.CSharp.win</PackageId>
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved
<!--Set NuGet Message-->
<Title>OpenVINO C# API</Title>
<Version>3.1.1</Version>
<Authors>Guojin Yan</Authors>
<Company>Guojin Yan</Company>
<Product>OpenVINO C# API</Product>
<Description>Based on the C # platform, call the OpenVINO suite to deploy a deep learning model.
</Description>
<PackageProjectUrl>https://github.com/guojin-yan/OpenVINO-CSharp-API</PackageProjectUrl>
<RepositoryUrl>https://github.com/guojin-yan/OpenVINO-CSharp-API</RepositoryUrl>
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved
<RepositoryType>git</RepositoryType>
<PackageOutputPath>../../nuget</PackageOutputPath>
<NeutralLanguage>zh</NeutralLanguage>
<PackageReleaseNotes>This version is a pre release version of OpenVINO™ C# API 3.0 and its features are not yet fully developed. If there are any issues during use, please feel free to contact me.</PackageReleaseNotes>
<RootNamespace>OpenVinoSharp</RootNamespace>
<AssemblyName>OpenVINOCSharp</AssemblyName>
</PropertyGroup>


<!--Add build file.-->
<ItemGroup>
<None Include=".\build\openvino2023.1\*.*">
<Pack>true</Pack>
<PackagePath>build\openvino2023.1\%(Filename)%(Extension)</PackagePath>
</None>
</ItemGroup>


<ItemGroup Condition=" '$(TargetFramework)' == 'net48'">
<Reference Include="System.Security" />
<Reference Include="System.Web" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.8.0.20230708" />
<PackageReference Include="OpenCvSharp4.Windows" Version="4.8.0.20230708" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="build\OpenVINO.CSharp.win.targets">
<Pack>true</Pack>
<PackagePath>build\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="exception\" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net48'">
<DefineConstants>$(DefineConstants);DOTNET_FRAMEWORK;</DefineConstants>
</PropertyGroup>


</Project>
25 changes: 25 additions & 0 deletions modules/csharp_api/csharp/CSharpAPI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpAPI", "CSharpAPI.csproj", "{56A1269F-3928-4367-84BE-0EA2877DFED1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{56A1269F-3928-4367-84BE-0EA2877DFED1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56A1269F-3928-4367-84BE-0EA2877DFED1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56A1269F-3928-4367-84BE-0EA2877DFED1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56A1269F-3928-4367-84BE-0EA2877DFED1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {79883B4A-4EAE-42DE-A72B-7B6D47685E9A}
EndGlobalSection
EndGlobal
70 changes: 70 additions & 0 deletions modules/csharp_api/csharp/base.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace OpenVinoSharp
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved
{

/// <summary>
/// OpenVINO wrapper for .NET.
/// This is the basic namespace of OpenVINO in Cshrp,
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved
/// and all classes and methods are within this method.
/// <c>OpenVinoSharp</c>.
/// </summary>
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
class NamespaceDoc
{
}

namespace element {
/// <summary>
/// OpenVINO wrapper for .NET.
/// Define elements in OpenVINO.
/// <c>OpenVinoSharp.element</c>.
/// </summary>
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
class NamespaceDoc
{
}
}


namespace preprocess {
/// <summary>
/// Mainly defined the data processing methods in OpenVINO.
/// <c>OpenVinoSharp.preprocess</c>.
/// </summary>
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
class NamespaceDoc
{
}
}


namespace model
{
/// <summary>
/// Processing methods for main common models.
/// <c>OpenVinoSharp.model</c>.
/// </summary>
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
class NamespaceDoc
{
}
namespace Yolov8 {
guojin-yan marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// The processing methods of the main Yolov8 model.
/// <c>OpenVinoSharp.model.Yolov8</c>.
/// </summary>
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
class NamespaceDoc
{
}
}
}
}


10 changes: 10 additions & 0 deletions modules/csharp_api/csharp/build/OpenVINO.CSharp.win.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup >
<None Include="$(MSBuildThisFileDirectory)\openvino2023.1\*.*">
<Link>%(RecursiverDir)openvino2023.1/%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions modules/csharp_api/csharp/build/openvino2023.1/plugins.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ie>
<plugins>
<plugin name="NPU" location="openvino_intel_npu_plugin.dll">
</plugin>
</plugins>
</ie>
Loading
Loading