Ask Your Question

Juventi's profile - activity

2017-10-04 17:18:45 -0600 marked best answer DNN module forward() problem

cv::dnn::Net net = cv::dnn::readNetFromTensorflow(modelTxt); cv::Mat output = net.forward();

when use dnn module, import a tensorflow model successfully, then do the forward() calculation, a error throw:

OpenCV Error: Assertion failed (start < (int)shape.size() && end <= (int)shape.size() && start <= en
d) in cv::dnn::experimental_dnn_v1::total, file D:\software\opencv\opencv-3.3.0\modules\dnn\include\
opencv2/dnn/shape_utils.hpp, line 159

the assert is here:

static inline int total(const MatShape& shape, int start = -1, int end = -1)
    ...
    CV_Assert(start < (int)shape.size() && end <= (int)shape.size() &&
              start <= end);
    ...

My Graph is

def cnn_net(_X, n_classes, imagesize, img_channel):

   with tf.name_scope('ConvLayer1'):

        W_conv1 = weight_variable([5,5,3,32])
        b_conv1 = bias_variable([32])
        l_conv1 = tf.nn.relu(tf.nn.conv2d(_X,W_conv1, strides=[1,1,1,1],padding='SAME') + b_conv1)
        l_pool1 = tf.nn.max_pool(l_conv1, ksize=[1,2,2,1], strides=[1,2,2,1], padding='SAME')

    with tf.name_scope('ConvLayer2'):

        W_conv2 = weight_variable([5,5,32,64])
        b_conv2 = bias_variable([64])
        l_conv2 = tf.nn.relu(tf.nn.conv2d(l_pool1, W_conv2, strides=[1,1,1,1], padding='SAME')+b_conv2)
        l_pool2 = tf.nn.max_pool(l_conv2, ksize=[1,2,2,1],strides=[1,2,2,1], padding='SAME')

    with tf.name_scope('fcLayer1'):

        W_fc1 = weight_variable([64*8*8, 1024])
        b_fc1 = bias_variable([1024])
        l_pool2_flat = tf.reshape(l_pool2, [-1, 64*8*8])
        l_fc1 = tf.nn.relu(tf.matmul(l_pool2_flat, W_fc1) + b_fc1)

    with tf.name_scope('fcLayer2'):

        W_fc2 = weight_variable([1024, n_classes])
        b_fc2 = bias_variable([n_classes])
        y_conv = tf.matmul(l_fc1, W_fc2) + b_fc2

    return y_conv


x = tf.placeholder(tf.float32, name='inputs_placeholder', shape = [None, 32,32,3])
y = tf.placeholder(tf.int32, name='labels_placeholder', shape = [None, n_classes])

pred = cnn_net(x,n_classes, imagesize, img_channel)  
Y_re = tf.nn.softmax(pred,  name="y_pre")


Input : inputs_placeholder
Output: y_pre

this is my graph, i've already exclude dropout and other components that cannot import in Opencv

and the model is imported successfully, but i cannot foward with an single input image

BTW, by which way can you show the .pb file in the text window( at Github before) ?

2017-09-20 20:41:13 -0600 commented answer DNN module forward() problem

sure I will try it ..

2017-09-20 01:30:33 -0600 commented answer DNN module forward() problem

the reason may be , if I use '+' or tf.add, the shape of bias is not certain? but tf.nn.bias_add can make sure the bia

2017-09-20 01:19:54 -0600 commented answer DNN module forward() problem

...I think i've fixed it..... y_conv = tf.matmul(l_fc1, W_fc2) + b_fc2 should be repalced with: Y_re = tf.matmul(l_fc

2017-09-20 01:19:35 -0600 commented answer DNN module forward() problem

...I think i've fixed it..... y_conv = tf.matmul(l_fc1, W_fc2) + b_fc2 should be repalced with: Y_re = tf.matmul(l_fc

2017-09-19 23:15:39 -0600 commented answer DNN module forward() problem

yes...opencv 3.3 i downloaded 2 days ago it's strange a more complex tf_model is runing in opencv ok, but this simple o

2017-09-19 04:17:19 -0600 edited question DNN module forward() problem

DNN module forward() problem cv::dnn::Net net = cv::dnn::readNetFromTensorflow(modelTxt); cv::Mat output = net.forward()

2017-09-19 04:17:02 -0600 edited question DNN module forward() problem

DNN module forward() problem cv::dnn::Net net = cv::dnn::readNetFromTensorflow(modelTxt); cv::Mat output = net.forward()

2017-09-19 04:16:40 -0600 edited question DNN module forward() problem

DNN module forward() problem cv::dnn::Net net = cv::dnn::readNetFromTensorflow(modelTxt); cv::Mat output = net.forward()

2017-09-19 04:15:19 -0600 commented question DNN module forward() problem

hi, i've posted my graph..

2017-09-19 04:14:57 -0600 commented question DNN module forward() problem

hi, i've post my graph..

2017-09-19 04:14:32 -0600 received badge  Editor (source)
2017-09-19 04:14:32 -0600 edited question DNN module forward() problem

DNN module forward() problem cv::dnn::Net net = cv::dnn::readNetFromTensorflow(modelTxt); cv::Mat output = net.forward()

2017-09-19 00:10:22 -0600 asked a question DNN module forward() problem

DNN module forward() problem cv::dnn::Net net = cv::dnn::readNetFromTensorflow(modelTxt); cv::Mat output = net.forward()