Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem with concat in cv::dnn?

I have the following code https://pastebin.com/DLfCRjd4 that uses the following model https://drive.google.com/open?id=17ZsYNIUSL3UUCr8d2CdtzaiUYoZTSLtf that was created with the following tensorflow code https://pastebin.com/j8q7GFfW

It is supposed to receive an 128x128 grayscale image as input, load the network from the file above, and then get the tensor of the last layer, which is a fully-connected layer. However, I'm getting the following error for both Opencv 3.3 and the master branch:

OpenCV 3.3

OpenCV Error: Assertion failed (srcMat.dims == 2 && srcMat.cols == weights.cols && dstMat.rows == srcMat.rows && dstMat.cols == weights.rows && srcMat.type() == weights.type() && weights.type() == dstMat.type() && srcMat.type() == CV_32F && (biasMat.empty() || (biasMat.type() == srcMat.type() && biasMat.isContinuous() && (int)biasMat.total() == dstMat.cols))) in run, file /home/mauricio/Libraries/OpenCV3.3/opencv-3.3.0/modules/dnn/src/layers/fully_connected_layer.cpp, line 132
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/mauricio/Libraries/OpenCV3.3/opencv-3.3.0/modules/dnn/src/layers/fully_connected_layer.cpp:132: error: (-215) srcMat.dims == 2 && srcMat.cols == weights.cols && dstMat.rows == srcMat.rows && dstMat.cols == weights.rows && srcMat.type() == weights.type() && weights.type() == dstMat.type() && srcMat.type() == CV_32F && (biasMat.empty() || (biasMat.type() == srcMat.type() && biasMat.isContinuous() && (int)biasMat.total() == dstMat.cols)) in function run

master branch

OpenCV Error: Assertion failed (srcMat.dims == 2 && srcMat.cols == weights.cols && dstMat.rows == srcMat.rows && dstMat.cols == weights.rows && srcMat.type() == weights.type() && weights.type() == dstMat.type() && srcMat.type() == 5 && (biasMat.empty() || (biasMat.type() == srcMat.type() && biasMat.isContinuous() && (int)biasMat.total() == dstMat.cols))) in run, file /home/mauricio/Libraries/OpenCVmaster/opencv/modules/dnn/src/layers/fully_connected_layer.cpp, line 152
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/mauricio/Libraries/OpenCVmaster/opencv/modules/dnn/src/layers/fully_connected_layer.cpp:152: error: (-215) srcMat.dims == 2 && srcMat.cols == weights.cols && dstMat.rows == srcMat.rows && dstMat.cols == weights.rows && srcMat.type() == weights.type() && weights.type() == dstMat.type() && srcMat.type() == 5 && (biasMat.empty() || (biasMat.type() == srcMat.type() && biasMat.isContinuous() && (int)biasMat.total() == dstMat.cols)) in function run

I found out that the problem is not in the fully connected layer itself, but actually before it. I have the following layers in my model:

Conv2D 1
add 2
Relu 3
Conv2D_1 4
add_1 5
Relu_1 6
MaxPool 7
Conv2D_2 8
add_2 9
Relu_2 10
MaxPool_1 11
Conv2D_3 12
add_3 13
Relu_3 14
MaxPool_2 15
Conv2D_4 16
add_4 17
Relu_4 18
MaxPool_3 19
Conv2D_5 20
add_5 21
Relu_5 22
Reshape 23
Reshape_1 24
concat 25
MatMul 26

The layers "Reshape" and "Reshape_1" have size 1x16384, so the layer "concat" should have size 1x32768, but it shows the same size of the layers it should be concatenating (1x16384). This is why the assertion for the size in the fully connected layer is failing. Any one has any idea why this is happening?