如何在dotnet核心上使用cntk加载onnx模型

时间:2018-08-22 20:37:57

标签: .net-core cntk onnx

我做了一个控制台应用程序,试图加载从互联网下载的onnx模型。

enter image description here

使用

加载
            var deviceDescriptor = DeviceDescriptor.CPUDevice;
            model = Function.Load(@"C:\dev\EarthML.CarConnect.StreamProcessor\apps\EarthML.CarConnect.StreamProcessor\Assets\FERPlus.onnx",deviceDescriptor,ModelFormat.ONNX);


            Variable inputVar = model.Arguments.Single();

            NDShape inputShape = inputVar.Shape;
            int imageWidth = inputShape[0];
            int imageHeight = inputShape[1];

            Console.WriteLine($"{ imageWidth}x{imageHeight}");

但是会引发以下异常:

System.ApplicationException: Failed to load model: 'Field 'type' of attr is required but missing.'

[CALL STACK]
    > CNTK::Internal::  UseSparseGradientAggregationInDataParallelSGD
    - CNTK::  XavierInitializer
    - CNTK::Function::  Load
    - CSharp_CNTK_Function__Load__SWIG_0
    - 00007FFF4CE2638E (SymFromAddr() error: The specified module could not be found.)


   at CNTK.Function._Load(String filepath, DeviceDescriptor computeDevice, ModelFormat format)
   at CNTK.Function.Load(String filepath, DeviceDescriptor computeDevice, ModelFormat format)
   at EarthML.CarConnect.StreamProcessor.EmotionRecognizer.LoadModelAsync() in C:\dev\EarthML.CarConnect.StreamProcessor\apps\EarthML.CarConnect.StreamProcessor\Program.cs:line 42
Press any key to continue . . .

有人知道为什么吗?

依赖项:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <LangVersion>latest</LangVersion>
  <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  <Platforms>AnyCPU;x64</Platforms>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="Assets\FERPlus.onnx" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="Assets\FERPlus.onnx" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="CNTK.CPUOnly" Version="2.6.0-rc0.dev20180821" />
    <PackageReference Include="OpenCvSharp3-AnyCPU" Version="3.4.1.20180319" />
  </ItemGroup>

</Project>

repro:https://github.com/pksorensen/cntk-issue-26

0 个答案:

没有答案