Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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); ...

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) ?

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'):

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'): 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'): 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'): 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

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) ?

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):

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'):

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'):

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'):

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

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) ?

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): 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) ?

click to hide/show revision 6
None

updated 2017-09-19 04:40:55 -0600

berak gravatar image

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

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):

img_channel): with tf.name_scope('ConvLayer1'):

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])

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

name="y_pre") Input : inputs_placeholder Output: y_pre

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) ?