来自 MEX 文件的意外标准异常(pytorch 模型向前) [英] Unexpected Standard exception from MEX file (pytorch model forward)

查看:310
本文介绍了来自 MEX 文件的意外标准异常(pytorch 模型向前)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从 Matlab 调用 mex api 时,出现了意外的标准异常.

When I call mex api from Matlab, I got an unexpected standard exception.

我将 2 个 pytorch DNN 模型导出到A.pt"和B.pt"文件.

I exported 2 pytorch DNN models to 'A.pt' and 'B.pt' files.

并且我实现了从.pt"文件加载模型并运行模型(向前)的 C++ 函数.

And I implemented c++ functions that load models from the '.pt 'files and run models (forward).

c++ 实现工作正常,我可以从模型中得到正确的结果.

The c++ implementation works fine, I can get proper results from the models.

我构建了负载 &将前向函数运行到 '.dll' 库中,我实现了一个可以调用它们的 mex api 函数.

I built the load & run forward function into '.dll' library, and I implemented a mex api function can call them.

当我在Matlab环境中调用mex api时,2个模型加载正常,第一个模型正常向前运行.

When I call the mex api in Matlab environment, the 2 models are loaded normally, and the first model runs forward properly.

然而,当运行第二个模型时,我得到了以下异常.

However, when run forward the 2nd model, I got the following exception.

来自 MEX 文件的意外标准异常

Unexpected Standard exception from MEX file

What():以下操作在 TorchScript 解释器中失败.

What():The following operation failed in the TorchScript interpreter.

TorchScript 的回溯(最近一次调用):

Traceback of TorchScript (most recent call last):

运行时错误:TorchScript 解释器中的以下操作失败.

RuntimeError: The following operation failed in the TorchScript interpreter.

TorchScript 的回溯(最近一次调用):

Traceback of TorchScript (most recent call last):

运行时错误:LoadLibraryA 中的错误

RuntimeError: error in LoadLibraryA

我不知道为什么 c++ 实现可以正常工作,但是当通过 Matlab 的 mex api 调用它时会发生异常.

I have no clue why the c++ implementation works fine but the exception occurs when call it through mex api from Matlab.

因为负载&run forward 函数没有改变,我期望得到完全相同的结果.

Because the load & run forward functions are unchanged I expected the exactly same results.

因为没有调用堆栈打印,所以调试起来比较困难.

It is more difficult to debug because there is no call-stack print.

有什么办法可以得到调用栈吗?

Is there any way to get call-stack ?

请给我任何建议.

提前致谢.

-环境------------------------------

-environment-------------------------------

c++ 编译器:visual studio 2017 社区

c++ compiler : visual studio 2017 community

matlab : R2020a

matlab : R2020a

libtorch : 1.6

libtorch : 1.6

pytorch : 1.5

pytorch : 1.5

蟒蛇:3.6

cuda:10.2

推荐答案

根据 Cris Luengo 先生的评论,我通过将所有 libtorch dll 复制到 Matlab 自己的 bin 文件夹中解决了这个问题.有几个重复的文件,但我覆盖了它们.我不确定它是否安全,因此备份以前的 dll 可能是不错的选择.谢谢 Cris Luengo 先生.

From Mr. Cris Luengo's comments, I solved this problem by copying all libtorch dlls into Matlab's own bin folder. There are several duplicated files but I overwrote them. I'm not sure it is safe or not, so may be backup of previous dlls is good choice. Thank you Mr. Cris Luengo.

这篇关于来自 MEX 文件的意外标准异常(pytorch 模型向前)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆