Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Cannot apply tensorflow model

Hello I have problem with applying tensorflow model in OpenCV. The code below properly load model, but when calling forward method Assertion error is thrown. Do you have any ideas where is the problem? Or how to debug/find it?

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

Error:

Debug Assertion Failed!

Program: C:\Workspace\ImageAnalysisPlus\x64\Debug\opencv_world3410d.dll File: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector Line: 1789

Expression: back() called on empty vector

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

OpenCV version: 4.4.0

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

Platform: Windows 10, Visual Studio 2017

Thank you in advance for any advice.

Cannot apply tensorflow model

Hello I have problem with applying tensorflow model in OpenCV. The code below properly load model, but when calling forward method Assertion error is thrown. Do you have any ideas where is the problem? Or how to debug/find it?

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

Error:

Debug Assertion Failed!

Program: C:\Workspace\ImageAnalysisPlus\x64\Debug\opencv_world3410d.dll File: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\vector Line: 1789

Expression: back() called on empty vector

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

OpenCV version: 4.4.0

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

Platform: Windows 10, Visual Studio 2017

Thank you in advance for any advice.

Edit

Now I tried to load the model in python and OpenCV and it works.