Ask Your Question
0

Cannot apply tensorflow model

asked 2020-09-22 01:22:07 -0600

Wex gravatar image

updated 2020-09-22 07:20:37 -0600

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-10-05 00:57:21 -0600

Wex gravatar image

I have to admit that I didn't try the posted minimal code. It was part of a little bigger code. The minimal code works also on my machine. Knowing that I found out that I was calling the forward method on uninitialized network which caused the error. I initialized local net variable in init method in a class instead of a class attribute.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-09-22 01:22:07 -0600

Seen: 409 times

Last updated: Oct 05 '20