Ask Your Question

Revision history [back]

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting an error "vector subscript out of range"

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

Code used to create model

image description

Code to load and run model

image description

Error and console output

image description

image description

click to hide/show revision 2
None

updated 2018-03-27 11:42:14 -0600

berak gravatar image

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting an error "vector subscript out of range"

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

Code used to create model

image description

Code to load and run model

image description

Error and console output

image description

image description

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting an error "vector the error: "Vector subscript out of range"range" and an "Initialize openCL runtime" warning

I can access the nets layers and print the names, i have also printed out the Mat img dimensions and they match the input size of the model i created.

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

Code used to load model and perform forward pass

int main(int argc, char** argv)
{
    String modelFile = "graph.pb";
    String imageFile = "7img.png";

    Net net = readNetFromTensorflow(modelFile);
    Mat img = imread(imageFile, IMREAD_GRAYSCALE);

    // check if model loaded and print layers
    if (net.empty())
    {
        cout << endl << "net empty" << endl;
        exit(0);
        ...
    }
    else {
        cout << endl << "success" << endl;
        vector<String> names = net.getLayerNames();
    }

    cout << endl << img.cols << " img cols" << endl;
    cout << img.rows << " img rows" << endl;
    cout << img.channels() << " img channel(s)" << endl;

    net.setInput(img);
    Mat results = net.forward(); // ERROR HERE

    return 0;
}

Code used to create and save model

import tensorflow as tf
import tensorflow.contrib.keras as K
import numpy as np

# Define the model in Keras
model = K.models.Sequential()

model.add(K.layers.Conv2D(32,kernel_size=(3,3),input_shape=(28,28,1)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Conv2D(32,kernel_size=(3,3)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.MaxPooling2D(pool_size=(2,2)))

a,b,c,d = model.output_shape
a = b*c*d

model.add(K.layers.Permute([1, 2, 3]))  # Indicate NHWC data layout
model.add(K.layers.Reshape((a,)))

model.add(K.layers.Dense(128))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Dense(10))
model.add(K.layers.Activation('softmax'))

# Get Keras prediction
inp = np.random.standard_normal([1, 28, 28, 1]).astype(np.float32)
tf_out = model.predict(inp)

# Serialize the graph
sess = K.backend.get_session()
constant_graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ['activation_4/Softmax'])
tf.train.write_graph(constant_graph, "", "graphtext.txt", as_text=True)

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting the error: "Vector subscript out of range" and an "Initialize openCL runtime" warning

I can access the nets layers and print the names, i have also printed out the Mat img dimensions and they match the input size of the model i created.

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

Code used to load model and perform forward pass

int main(int argc, char** argv)
{
    String modelFile = "graph.pb";
    String imageFile = "7img.png";

    Net net = readNetFromTensorflow(modelFile);
    Mat img = imread(imageFile, IMREAD_GRAYSCALE);

    // check if model loaded and print layers
    if (net.empty())
    {
        cout << endl << "net empty" << endl;
        exit(0);
        ...
    }
    else {
        cout << endl << "success" << endl;
        vector<String> names = net.getLayerNames();
    }

    cout << endl << img.cols << " img cols" << endl;
    cout << img.rows << " img rows" << endl;
    cout << img.channels() << " img channel(s)" << endl;

    net.setInput(img);
    Mat results = net.forward(); // ERROR HERE

    return 0;
}

Code used to create and save model

import tensorflow as tf
import tensorflow.contrib.keras as K
import numpy as np

# Define the model in Keras
model = K.models.Sequential()

model.add(K.layers.Conv2D(32,kernel_size=(3,3),input_shape=(28,28,1)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Conv2D(32,kernel_size=(3,3)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.MaxPooling2D(pool_size=(2,2)))

a,b,c,d = model.output_shape
a = b*c*d

model.add(K.layers.Permute([1, 2, 3]))  # Indicate NHWC data layout
model.add(K.layers.Reshape((a,)))

model.add(K.layers.Dense(128))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Dense(10))
model.add(K.layers.Activation('softmax'))

# Get Keras prediction
inp = np.random.standard_normal([1, 28, 28, 1]).astype(np.float32)
tf_out = model.predict(inp)

# Serialize the graph
sess = K.backend.get_session()
constant_graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ['activation_4/Softmax'])
tf.train.write_graph(constant_graph, "", "graphtext.txt", as_text=True)

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting the error: "Vector subscript out of range" and an "Initialize openCL runtime" warning

I can access the nets layers and print the names, i have also printed out the Mat img dimensions and they match the input size of the model i created.

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

Code used to load model and perform forward pass

int main(int argc, char** argv)
{
    String modelFile = "graph.pb";
    String imageFile = "7img.png";

    Net net = readNetFromTensorflow(modelFile);
    Mat img = imread(imageFile, IMREAD_GRAYSCALE);

    // check if model loaded and print layers
    if (net.empty())
    {
        cout << endl << "net empty" << endl;
        exit(0);
        ...
    }
    else {
        cout << endl << "success" << endl;
        vector<String> names = net.getLayerNames();
    }

    cout << endl << img.cols << " img cols" << endl;
    cout << img.rows << " img rows" << endl;
    cout << img.channels() << " img channel(s)" << endl;

    net.setInput(img);
    Mat results = net.forward(); // ERROR HERE

    return 0;
}

Code used to create and save model

import tensorflow as tf
import tensorflow.contrib.keras as K
import numpy as np

# Define the model in Keras
model = K.models.Sequential()

model.add(K.layers.Conv2D(32,kernel_size=(3,3),input_shape=(28,28,1)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Conv2D(32,kernel_size=(3,3)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.MaxPooling2D(pool_size=(2,2)))

a,b,c,d = model.output_shape
a = b*c*d

model.add(K.layers.Permute([1, 2, 3]))  # Indicate NHWC data layout
model.add(K.layers.Reshape((a,)))

model.add(K.layers.Dense(128))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Dense(10))
model.add(K.layers.Activation('softmax'))

# Get Keras prediction
inp = np.random.standard_normal([1, 28, 28, 1]).astype(np.float32)
tf_out = model.predict(inp)

# Serialize the graph
sess = K.backend.get_session()
constant_graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ['activation_4/Softmax'])
tf.train.write_graph(constant_graph, "", "graphtext.txt", as_text=True)

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting the error: "Vector subscript out of range" and an "Initialize openCL runtime" warning

I can access the nets layers and print the names, i have also printed out the Mat img dimensions and they match the input size of the model i created.

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

Code used to load model and perform forward pass

int main(int argc, char** argv)
{
    String modelFile = "graph.pb";
    String imageFile = "7img.png";

    Net net = readNetFromTensorflow(modelFile);
    Mat img = imread(imageFile, IMREAD_GRAYSCALE);

    // check if model loaded and print layers
    if (net.empty())
    {
        cout << endl << "net empty" << endl;
        exit(0);
        ...
    }
    else {
        cout << endl << "success" << endl;
        vector<String> names = net.getLayerNames();
    }

    cout << endl << img.cols << " img cols" << endl;
    cout << img.rows << " img rows" << endl;
    cout << img.channels() << " img channel(s)" << endl;

    net.setInput(img);
    Mat results = net.forward(); // ERROR HERE

    return 0;
}

Code used to create and save model

import tensorflow as tf
import tensorflow.contrib.keras as K
import numpy as np

# Define the model in Keras
model = K.models.Sequential()

model.add(K.layers.Conv2D(32,kernel_size=(3,3),input_shape=(28,28,1)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Conv2D(32,kernel_size=(3,3)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.MaxPooling2D(pool_size=(2,2)))

a,b,c,d = model.output_shape
a = b*c*d

model.add(K.layers.Permute([1, 2, 3]))  # Indicate NHWC data layout
model.add(K.layers.Reshape((a,)))

model.add(K.layers.Dense(128))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Dense(10))
model.add(K.layers.Activation('softmax'))

# Get Keras prediction
inp = np.random.standard_normal([1, 28, 28, 1]).astype(np.float32)
tf_out = model.predict(inp)

# Serialize the graph
sess = K.backend.get_session()
constant_graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ['activation_4/Softmax'])
tf.train.write_graph(constant_graph, "", "graphtext.txt", as_text=True)

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting the error: "Vector subscript out of range" and an "Initialize openCL runtime" warning

I can access the nets layers and print the names, i have also printed out the Mat img dimensions and they match the input size of the model i created.

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

Code used to load model and perform forward pass

int main(int argc, char** argv)
{
    String modelFile = "graph.pb";
    String imageFile = "7img.png";

    Net net = readNetFromTensorflow(modelFile);
    Mat img = imread(imageFile, IMREAD_GRAYSCALE);

    // check if model loaded and print layers
    if (net.empty())
    {
        cout << endl << "net empty" << endl;
        exit(0);
        ...
    }
    else {
        cout << endl << "success" << endl;
        vector<String> names = net.getLayerNames();
    }

    cout << endl << img.cols << " img cols" << endl;
    cout << img.rows << " img rows" << endl;
    cout << img.channels() << " img channel(s)" << endl;

    net.setInput(img);
    Mat results = net.forward(); // ERROR HERE

    return 0;
}

Code used to create and save model

import tensorflow as tf
import tensorflow.contrib.keras as K
import numpy as np

# Define the model in Keras
model = K.models.Sequential()

model.add(K.layers.Conv2D(32,kernel_size=(3,3),input_shape=(28,28,1)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Conv2D(32,kernel_size=(3,3)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.MaxPooling2D(pool_size=(2,2)))

a,b,c,d = model.output_shape
a = b*c*d

model.add(K.layers.Permute([1, 2, 3]))  # Indicate NHWC data layout
model.add(K.layers.Reshape((a,)))

model.add(K.layers.Dense(128))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Dense(10))
model.add(K.layers.Activation('softmax'))

# Get Keras prediction
inp = np.random.standard_normal([1, 28, 28, 1]).astype(np.float32)
tf_out = model.predict(inp)

# Serialize the graph
sess = K.backend.get_session()
constant_graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ['activation_4/Softmax'])
tf.train.write_graph(constant_graph, "", "graphtext.txt", as_text=True)

Dnn.forward(), vector subscript out of range

I have loaded a model but when doing evaluation using Net.forward() i am getting the error: "Vector subscript out of range" and an "Initialize openCL runtime" warning

I can access the nets layers and print the names, i have also printed out the Mat img dimensions and they match the input size of the model i created.

Any help suggestions to what the error is or how i could solve it would be appreciated. Thank you.

graph.pb

graphtext.txt

Code used to load model and perform forward pass

int main(int argc, char** argv)
{
    String modelFile = "graph.pb";
    String imageFile = "7img.png";

    Net net = readNetFromTensorflow(modelFile);
    Mat img = imread(imageFile, IMREAD_GRAYSCALE);

    // check if model loaded and print layers
    if (net.empty())
    {
        cout << endl << "net empty" << endl;
        exit(0);
        ...
    }
    else {
        cout << endl << "success" << endl;
        vector<String> names = net.getLayerNames();
    }

    cout << endl << img.cols << " img cols" << endl;
    cout << img.rows << " img rows" << endl;
    cout << img.channels() << " img channel(s)" << endl;

    net.setInput(img);
    Mat results = net.forward(); // ERROR HERE

    return 0;
}

Code used to create and save model

import tensorflow as tf
import tensorflow.contrib.keras as K
import numpy as np

# Define the model in Keras
model = K.models.Sequential()

model.add(K.layers.Conv2D(32,kernel_size=(3,3),input_shape=(28,28,1)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Conv2D(32,kernel_size=(3,3)))
model.add(K.layers.Activation('relu'))

model.add(K.layers.MaxPooling2D(pool_size=(2,2)))

a,b,c,d = model.output_shape
a = b*c*d

model.add(K.layers.Permute([1, 2, 3]))  # Indicate NHWC data layout
model.add(K.layers.Reshape((a,)))

model.add(K.layers.Dense(128))
model.add(K.layers.Activation('relu'))

model.add(K.layers.Dense(10))
model.add(K.layers.Activation('softmax'))

# Get Keras prediction
inp = np.random.standard_normal([1, 28, 28, 1]).astype(np.float32)
tf_out = model.predict(inp)

# Serialize the graph
sess = K.backend.get_session()
constant_graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph.as_graph_def(), ['activation_4/Softmax'])
tf.train.write_graph(constant_graph, "", "graphtext.txt", as_text=True)