简体   繁体   English

在不安装 Microsoft.ML.OnnxRuntime 的情况下使用 ML.NET model 实例化 class nuget package

[英]Instantiating a class with ML.NET model without installing Microsoft.ML.OnnxRuntime nuget package

I am using ML.NET services我正在使用 ML.NET 服务

I've created and trained an ONNX model, created a library to working with a trained model. But there is a problem我已经创建并训练了一个 ONNX model,创建了一个库来与训练有素的 model 一起工作。但是有一个问题

Any application that uses the library I created requires the Microsoft.ML.OnnxRuntime nuget package to be installed.任何使用我创建的库的应用程序都需要安装 Microsoft.ML.OnnxRuntime nuget package。

My library needs to be used in a deployed 3rd party application where installing nuget packages is not allowed, but it is possible to add DLLs.我的库需要在已部署的第 3 方应用程序中使用,其中不允许安装 nuget 包,但可以添加 DLL。 In addition to dll libraries, nothing can be added, config files cannot be added too.除了dll库,什么都不能加,配置文件也不能加。

I've tried adding dlls which are installed by Microsoft.ML.OnnxRuntime nuget package:我尝试添加由 Microsoft.ML.OnnxRuntime nuget package 安装的 dll:

  • Microsoft.ML.OnnxRuntime; Microsoft.ML.OnnxRuntime;
  • System.Buffers;系统缓冲区;
  • System.Memory;系统.Memory;
  • System.Numerics;系统.数值;
  • System.Numerics.Vectors;系统.数值.向量;
  • System.Runtime.CompilerServices.Unsafe. System.Runtime.CompilerServices.Unsafe。

But I didn't get the right result.但是我没有得到正确的结果。 Instantiating a class from my library causes an exception:从我的库中实例化 class 会导致异常:

'The type initializer for' Microsoft.ML.OnnxRuntime.NativeMethods 'threw an exception.' “Microsoft.ML.OnnxRuntime.NativeMethods 的类型初始值设定项引发异常。” EntryPointNotFoundException: Unable to find an entry point named 'OrtGetApiBase' in DLL 'onnxruntime'. EntryPointNotFoundException:无法在 DLL“onnxruntime”中找到名为“OrtGetApiBase”的入口点。

Is it possible to fix the problem without installing the Microsoft.ML.OnnxRuntime nuget package into the application to use my library?是否可以在不将 Microsoft.ML.OnnxRuntime nuget package 安装到应用程序以使用我的库的情况下解决问题?

Problem is that the Microsoft.ML.OnnxRuntime library is loading the native onnxruntime.dll.问题是 Microsoft.ML.OnnxRuntime 库正在加载本机 onnxruntime.dll。

Therefore, in addition to installing the reference for the above libraries, it is necessary to copy the onnxruntime.dll library to the application folder.因此,除了安装上述库的引用外,还需要将onnxruntime.dll库复制到application文件夹中。

onnxruntime.dll be taken from the nuget package onnxruntime.dll取自nuget package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM