Skip to content

Latest commit

 

History

History
150 lines (105 loc) · 9.48 KB

README_cn.md

File metadata and controls

150 lines (105 loc) · 9.48 KB

OpenVINO™ C# API

简体中文| English

📚 简介

OpenVINO™ 是一个用于优化和部署 AI 推理的开源工具包。

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

  OpenVINO™ C# API 是一个 OpenVINO™ 的 .Net wrapper,应用最新的 OpenVINO™ 库开发,通过 OpenVINO™ C API 实现 .Net 对 OpenVINO™ Runtime 调用,使用习惯与 OpenVINO™ C++ API 一致。OpenVINO™ C# API 由于是基于 OpenVINO™ 开发,所支持的平台与 OpenVINO™ 完全一致,具体信息可以参考 OpenVINO™。通过使用 OpenVINO™ C# API,可以在 .NET、.NET Framework等框架下使用 C# 语言实现深度学习模型在指定平台推理加速。

NuGet Package

Core Managed Libraries

Package Description Link
OpenVINO.CSharp.API OpenVINO C# API core libraries NuGet Gallery
OpenVINO.CSharp.API.Extensions OpenVINO C# API core extensions libraries NuGet Gallery
OpenVINO.CSharp.API.Extensions.OpenCvSharp OpenVINO C# API core extensions libraries use OpenCvSharp NuGet Gallery
OpenVINO.CSharp.API.Extensions.EmguCV OpenVINO C# API core extensions libraries use EmguCV NuGet Gallery

Native Runtime Libraries

Package Description Link
OpenVINO.runtime.win Native bindings for Windows NuGet Gallery
OpenVINO.runtime.ubuntu.22-x86_64 Native bindings for ubuntu.22-x86_64 NuGet Gallery
OpenVINO.runtime.ubuntu.20-x86_64 Native bindings for ubuntu.20-x86_64 NuGet Gallery
OpenVINO.runtime.ubuntu.18-x86_64 Native bindings for ubuntu.18-x86_64 NuGet Gallery
OpenVINO.runtime.debian9-arm64 Native bindings for debian9-arm64 NuGet Gallery
OpenVINO.runtime.debian9-armhf Native bindings for debian9-armhf NuGet Gallery
OpenVINO.runtime.centos7-x86_64 Native bindings for centos7-x86_64 NuGet Gallery
OpenVINO.runtime.rhel8-x86_64 Native bindings for rhel8-x86_64 NuGet Gallery
OpenVINO.runtime.macos-x86_64 Native bindings for macos-x86_64 NuGet Gallery
OpenVINO.runtime.macos-arm64 Native bindings for macos-arm64 NuGet Gallery

Integration Library

Package Description Link
OpenVINO.CSharp.Windows All-in-one package for Windows NuGet Gallery

⚙ 如何安装

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

Windows

通过dotnet add package指令安装或通过Visual Studio安装以下程序包

dotnet add package OpenVINO.CSharp.API
dotnet add package OpenVINO.runtime.win
或者安装集成包——>
dotnet add package OpenVINO.CSharp.Windows

Linux

   linux平台我们根据官方编译的平台制作了对应的NuGet Package,以ubuntu.22-x86_64为例,通过dotnet add package指令安装:

dotnet add package OpenVINO.CSharp.API
dotnet add package OpenVINO.runtime.ubuntu.22-x86_64

  运行一次程序后,添加环境变量:

export LD_LIBRARY_PATH={Program generated executable file directory}/runtimes/ubuntu.22-x86_64/native
例如——>
export LD_LIBRARY_PATH=/home/ygj/Program/sample1/bin/Debug/net6.0/runtimes/ubuntu.22-x86_64/native

  如果对于一个全新平台(未安装过OpenVINO C++),需要安装一下依赖环境,切换到{Program generated executable file directory}/runtimes/ubuntu.22-x86_64/native目录下,运行以下指令:

sudo -E ./install_openvino_dependencies.sh

Mac OS

通过dotnet add package指令安装以下程序包

dotnet add package OpenVINO.CSharp.API
dotnet add package OpenVINO.runtime.macos-arm64

🏷开始使用

  • 使用方法

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

using OpenVinoSharp;  // 引用命名空间
namespace test
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using Core core = new Core();  // 初始化 Core 核心
            using Model model = core.read_model("./model.xml");  // 读取模型文件
            using CompiledModel compiled_model = core.compiled_model(model, "AUTO");  // 将模型加载到设备
            using InferRequest infer_request = compiled_model.create_infer_request();  // 创建推理通道
            using Tensor input_tensor = infer_request.get_tensor("images");  // 获取输入节点Tensor
            infer_request.infer();  // 模型推理
            using Tensor output_tensor = infer_request.get_tensor("output0");  // 获取输出节点Tensor
        }
    }
}

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

💻 应用案例

获取耕读应用案例请参考:OpenVINO-CSharp-API-Samples

🗂 API 文档

如果想了解更多信息,可以参阅:OpenVINO™ C# API API Documented

🎖 贡献

  如果您对OpenVINO™ 在C#使用感兴趣,有兴趣对开源社区做出自己的贡献,欢迎加入我们,一起开发OpenVINO™ C# API。

  如果你对该项目有一些想法或改进思路,欢迎联系我们,指导下我们的工作。

许可证书

本项目的发布受Apache 2.0 license许可认证。