【问题标题】:Inference of onnx model (opset11) in Windows 10 c++?Windows 10 c++ 中 onnx 模型(opset11)的推断?
【发布时间】:2020-07-09 15:39:36
【问题描述】:

为了通过 WinML 使用我的自定义 TF 模型,我使用 tf2onnx 转换器将其转换为 onnx。转换最终使用 opset 11 进行。不幸的是,我无法在 WinRT c++ 库中加载模型,因此我对 opset 支持感到困惑:根据发行说明,5 月的最新 WinML 版本支持 opset 11。我更新了我的 VS2019 和下载了最新的 Windows 10 SDK,c++ API 是否已经包含最新的 onnx 支持?或者有没有其他方法可以在 WinML c++ 中使用我的模型?

【问题讨论】:

    标签: windows-runtime onnx onnxruntime windows-machine-learning


    【解决方案1】:

    最新版本的 Windows 操作系统包含对 opset 9 的支持。 Microsoft.AI.MachineLearning NuGet 包的最新版本包含对 opset 11 的支持。

    请参阅这些发行说明:https://docs.microsoft.com/en-us/windows/ai/windows-ml/release-notes

    您可以在此处找到最新的 Microsoft.AI.MachineLearning NuGet 包:https://www.nuget.org/packages/Microsoft.AI.MachineLearning/

    【讨论】:

      【解决方案2】:

      正如@Kookei 提到的,有两种构建 WinML 的方法:the "In-Box" way and the NuGet way

      In-Box 基本上只是意味着链接到 Windows 本身包含的任何 WinML DLL(例如,在 C:\Window\System32 中)。

      NuGet 包包含自己更新的 DLL 集,除了为最新的 ONNX opset 提供支持外,它还有一个明显的优势,即允许您轻松地将二进制文件分发到缺乏任何内置机器学习功能的旧版本 Windows能力。只需通过 Visual Studio 的 Nuget 包管理器安装包,然后构建您的解决方案;您会发现输出目录现在包含所需的 DLL(当前为 directml.dllMicrosoft.AI.MachineLearning.dllonnxruntime.dll)以及生成的 EXE,可用于同文件夹部署。

      从源码来看,两个版本是这样的distinguished

      收件箱:

      #include <winrt/Windows.AI.MachineLearning.h>
      using WinMLModel = winrt::windows::AI::MachineLearning
      

      NuGet:

      #include <winrt/Microsoft.AI.MachineLearning.h>
      using WinMLModel = winrt::Microsoft::AI::MachineLearning
      

      换句话说,唯一的区别是您使用的是Window 还是Microsoft 标头/命名空间。

      【讨论】:

      • 感谢您的回答。我注意到,当我通过 NuGet 包管理器安装 Microsoft.AI.MachineLearning 然后再次卸载它时,我的代码行为发生了变化。这是否也会更新 DirectML 和 onnxruntime 发行版?
      • @JamesTrüeb NuGet 包提供了完整的 ONNXRuntime→WinML→DirectML DLL 堆栈,卸载后应该完全消失,所以不;我认为这不会影响您的代码或安装在系统其他地方的任何其他类似发行版。 (如果这是一个您可以详细解释的问题,并且可以直接复制,那么这将是一个很好的单独问题。)
      【解决方案3】:

      您还可以在 version matrix 表中跟踪支持的 opset 版本。

      【讨论】:

        猜你喜欢
        • 2021-09-13
        • 2021-05-26
        • 1970-01-01
        • 2020-10-10
        • 2020-02-01
        • 2018-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多