Assertion failed in function total (dnn::forward) [closed]
Hello,
I'm facing a problem that I have no idea why it is happening. I have the following code:
#include <iostream>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace cv::dnn;
using namespace std;
int main(int argc, char **argv) {
dnn::Net net = readNetFromTensorflow(argv[1]);
if(net.empty()) exit(-1);
for(string s : net.getLayerNames())
cout << s << " " << net.getLayerId(s) << endl;
//Mat img(224, 224, CV_8UC3);
Mat img(96, 96, CV_8UC1);
Mat inputBlob = blobFromImage(img);
net.setInput(inputBlob);
//Mat result = net.forward("softmax2");
Mat result = net.forward("own_namespace_123/out/add");
for(int i=0; i < result.dims; i++)
cout << result.size[i] << " ";
cout << endl;
}
When I use the inception network from the example (https://storage.googleapis.com/downlo...), everything works:
conv2d0_pre_relu/conv 2
conv2d0 3
maxpool0 4
localresponsenorm0 5
conv2d1_pre_relu/conv 6
...
softmax1 158
avgpool0/reshape 159
softmax2_pre_activation/matmul 160
softmax2 161
1 1008
However, when a try to use my own network, the loading part works, but the forward function gives the following error:
OpenCV Error: Assertion failed (start < (int)shape.size() && end <= (int)shape.size() && start <= end) in total, file /home/mauricio/Libraries/OpenCV3.3/opencv-3.3.0/modules/dnn/include/opencv2/dnn/shape_utils.hpp, line 159
terminate called after throwing an instance of 'cv::Exception'
what(): /home/mauricio/Libraries/OpenCV3.3/opencv-3.3.0/modules/dnn/include/opencv2/dnn/shape_utils.hpp:159: error: (-215) start < (int)shape.size() && end <= (int)shape.size() && start <= end in function total
Aborted (core dumped)
Has anyone any idea why?
@Maups, we need to know what the network is. Can you share a graph definition?
Looks like I need to replace tf.add for tf.nn.bias_add, as said in other threads. Just discovered that by dumping input and output sizes and checking where it stops: