Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

DNN assertion failed in getMemoryShapes

Hello! I have a Tensorflow model with the following input:

    x = tf.placeholder(tf.float32, shape=[None, img_height, img_width], name='x_input')
    x_image = tf.reshape(x, [-1, img_height, img_width, num_channels])
    layer_conv1, weights_conv1 = new_conv_layer(input=x_image,
                                        num_input_channels=num_channels,
                                        filter_size=filter_size1,
                                        num_filters=num_filters1,
                                        use_pooling=True)
    ...
    y_pred = tf.nn.softmax(layer_fc2, name='prediction')   #layer with results
    ...

And I load it into the C ++ program as follows:

String modelFile = "frozen_model.pb";
dnn::Net net = readNetFromTensorflow(modelFile);

But when I try to upload an image:

Mat img = imread(imageFile, IMREAD_GRAYSCALE);
/*normalization here*/
Mat inputBlob = blobFromImage(img);
net.setInput(inputBlob, inBlobName);

I get the following error:

OpenCV Error: Assertion failed (ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0) in getMemoryShapes, file /home/vlad/opencv_3/opencv/modules/dnn/src/layers/convolution_layer.cpp, line 217 terminate called after throwing an instance of 'cv::Exception' what(): /home/vlad/opencv_3/opencv/modules/dnn/src/layers/convolution_layer.cpp:217: error: (-215) ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0 in function getMemoryShapes

Could you tell me what I'm doing wrong and how can I fix this error?

P.S. Below is the code for saving the mode:

output_node_names = "x_input,prediction"
constant_graph = tf.graph_util.convert_variables_to_constants(session, session.graph_def, output_node_names.split(','))
with tf.gfile.GFile('frozen_model.pb', "wb") as f:
    f.write(constant_graph.SerializeToString())

DNN assertion failed in getMemoryShapes

Hello! I have a Tensorflow model with the following input:

    x = tf.placeholder(tf.float32, shape=[None, img_height, img_width], name='x_input')
    x_image = tf.reshape(x, [-1, img_height, img_width, num_channels])
    layer_conv1, weights_conv1 = new_conv_layer(input=x_image,
                                        num_input_channels=num_channels,
                                        filter_size=filter_size1,
                                        num_filters=num_filters1,
                                        use_pooling=True)
    ...
    y_pred = tf.nn.softmax(layer_fc2, name='prediction')   #layer with results
    ...

And I load it into the C ++ program as follows:

String modelFile = "frozen_model.pb";
dnn::Net net = readNetFromTensorflow(modelFile);

But when I try to upload an image:

   //initialize network
    dnn::Net net = readNetFromTensorflow(modelFile);
    assert(!net.empty());
    //prepare blobas
    Mat img = imread(imageFile, IMREAD_GRAYSCALE);
/*normalization here*/
    assert(!img.empty());

    Mat fimg(img.size(), CV_32FC1);
    for (int i = 0;  i < img.rows; i++) {
        for (int j = 0; j < img.cols; j++){
            fimg.at<float>(i, j) = img.at<uint8_t>(i, j) / 255. - 0.5;
        }
    }

    Mat inputBlob = blobFromImage(img);
blobFromImage(fimg);
    net.setInput(inputBlob, inBlobName);

I get the following error:

OpenCV Error: Assertion failed (ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0) in getMemoryShapes, file /home/vlad/opencv_3/opencv/modules/dnn/src/layers/convolution_layer.cpp, line 217 terminate called after throwing an instance of 'cv::Exception' what(): /home/vlad/opencv_3/opencv/modules/dnn/src/layers/convolution_layer.cpp:217: error: (-215) ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0 in function getMemoryShapes

Could you tell me what I'm doing wrong and how can I fix this error?

P.S. Below is the code for saving the mode:

output_node_names = "x_input,prediction"
constant_graph = tf.graph_util.convert_variables_to_constants(session, session.graph_def, output_node_names.split(','))
with tf.gfile.GFile('frozen_model.pb', "wb") as f:
    f.write(constant_graph.SerializeToString())