无法在 OpenCV 中应用张量流模型

星河

您好,我在 OpenCV 中应用 tensorflow 模型时遇到问题。下面的代码正确加载模型,但在调用前向方法时抛出断言错误。你知道问题出在哪里吗?或者如何调试/找到它?

cv::dnn::Net net;
string path;
path = "graph.pb";
net = cv::dnn::readNetFromTensorflow(path);
if (net.empty())
{
    std::cerr << "Can't load network by using the given files." << std::endl;
    return ;
}
Mat image = imread(imagePath)
Mat inputBlob = cv::dnn::blobFromImage(image, 1.0, Size(512, 512), Scalar(0,0,0), true, false);
int N = inputBlob.size[0], C = inputBlob.size[1], H = inputBlob.size[2], W = inputBlob.size[3]; // [1, 3, 512, 512]
net.setInput(inputBlob);        //set the network input
Mat output = net.forward(); // <- throws error

错误

调试断言失败!

程序:C:\Workspace\ImageAnalysisPlus\x64\Debug\opencv_world3410d.dll 文件:C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector 行: 1789

表达式:back() 在空向量上调用

有关程序如何导致断言失败的信息,请参阅有关断言的 Visual C++ 文档。


OpenCV 版本:4.4.0

Tensorflow 模型:https ://drive.google.com/file/d/1aE0smAw-CyPLch6UY8blK3RreT5RrZfN/view ? usp = sharing

平台:Windows 10、Visual Studio 2017

我尝试在 python 和 OpenCV 中加载模型并且它工作正常。

预先感谢您的任何建议。

星河

我不得不承认我没有尝试发布的最小代码。它是一个更大的代码的一部分。最少的代码也适用于我的机器。知道我发现我在未初始化的网络上调用 forward 方法导致错误。我在类中的 init 方法中初始化了本地网络变量,而不是类属性。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章