ASP.NET Core 在 Docker 容器内加载 Onnx 文件

问题描述 投票:0回答:2

我正在尝试构建一个使用 Onnx 机器学习模型文件的 ASP.NET Core api。我像这样加载它:

OnnxScoringEstimator pipeline = _mlContext.Transforms.ApplyOnnxModel(_config.GetSection("ModelPath").Value);

这意味着它从 appsettings.json 文件获取路径,如下所示:

appsettings.Development.json

"ModelPath": "C:\\Users\\name\\dev\\solution\\project\\model.onnx"

以及我的 appsettings.Production.json

"ModelPath": "./model.onnx"

在我的机器上调试项目时它确实有效,但当我在 Docker 容器中构建它时则无效。然后它给出以下错误:

Connection id "0HLV880PG88DT", Request id "0HLV880PG88DT:00000002": An unhandled exception was thrown by the application.

System.DllNotFoundException: Unable to load shared library 'onnxruntime' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libonnxruntime: cannot open shared object file: No such file or directory

因为它说

No such file or directory
我会说这与我的模型路径错误有关,但我不确定。

希望有人能帮忙。谢谢

docker asp.net-core
2个回答
1
投票

我也遇到了这个问题,经过一番苦思冥想,我在 Github 问题中找到了一个对我有用的解决方案,该问题指向 ONNX 运行时系统要求文档:https://github.com/Microsoft/onnxruntime #系统要求

重点:

对于 Linux,系统必须有 libgomp.so.1,可以使用 apt-get install libgomp1 安装。

将以下命令添加到 Dockerfile 后,我的应用程序按预期工作:

RUN apt-get update && apt-get install -y libgomp1

0
投票

就我而言,我尝试在部署在 Azure 应用服务的 Linux 实例上的 Azure Function 中运行 ML.NET 和 ONNX。

我遇到了异常

System.DllNotFoundException: Unable to load shared library 'onnxruntime' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libonnxruntime: cannot open shared object file: No such file or directory

尝试应用 ONNX 模型时。

解决方案是将 libonnxruntime.so 文件从部署 /runtimes/linux-x64/native/ 文件夹复制到部署 /bin/ 文件夹。

© www.soinside.com 2019 - 2024. All rights reserved.