Tensorflow .pb file in c++, opencv, placeholder tensor 'y_true' with dtype float and shape [?,3]
up vote
0
down vote
favorite
The python code runs fine, but the c++ code needs some fixing:
Tensorflow .pb file in c++, opencv, placeholder tensor 'y_true' with dtype float and shape [?,3]
I am having trouble getting the correct formats for c++. I can run the code in python.
One error message I receive in c++ is: You must feed a value for placeholder tensor 'y_true' with dtype float and shape [?,3]
[[Node: y_true = Placeholderdtype=DT_FLOAT, shape=[?,3], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]
The error message is because the result is not returned to the correct size array in c++, but I am having trouble understanding how to fix this.
The code is below: the lines I'm not understanding are where to put y_test_images in the c++ code:
pythyon:
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
c++:
I think I should put t somewhere, but not sure where:
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
This is the line that is not returning the correct result
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
In python the following code works:
sess = tf.Session()
saver = tf.train.import_meta_graph('trained\break_up.meta')
sess.run(tf.global_variables_initializer())
saver.restore(sess, tf.train.latest_checkpoint('trained'))
graph = tf.get_default_graph()
y_pred = graph.get_tensor_by_name("y_pred:0")
x= graph.get_tensor_by_name("x:0")
y_true = graph.get_tensor_by_name("y_true:0")
y_test_images = np.zeros((1, 3))
images2 = np.array(images_tf, dtype=np.uint8)
images2 = images2.astype('float32')
images2 = np.multiply(images2, 1.0/255.0)
x_batch = images2.reshape(1, 32,32,3)
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
print(result[0,0],result[0,1],result[0,2])
I am having trouble with the y_test_images numpy array on the c++ side.
tensorflow::GraphDef graph_def;
std::string graphFile = "break_up2.pb";
tensorflow::Status graphLoadedStatus = ReadBinaryProto(tensorflow::Env::Default(),graphFile,&graph_def);
if (!graphLoadedStatus.ok()){
std::cout << graphLoadedStatus.ToString()<<std::endl;
return 1;
}
int node_count = graph_def.node_size();
for (int i = 0; i < node_count; i++)
{
auto n = graph_def.node(i);
std::cout<<"Names : "<< n.name() <<std::endl;
std::cout<<"OP : "<< n.op() <<std::endl;
}
std::unique_ptr<tensorflow::Session> session_inception(tensorflow::NewSession(tensorflow::SessionOptions()));
tensorflow::Status session_create_status = session_inception->Create(graph_def);
if (!session_create_status.ok()){
std::cout << session_create_status.ToString()<<std::endl;
return 1;
}
std::vector<tensorflow::Tensor> finalOutput;
std::string InputName = "x:0";
std::string OutputName = "y_true:0";
std::vector<float> data_y[3];
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
auto t_matrix = t.matrix<float>();
t_matrix(0, 0) = 1.0;
t_matrix(0, 1) = 0.5;
t_matrix(0, 2) = 0.0;
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
if (!run_status.ok()){
std::cout << run_status.ToString() << "n";
return 1;
}
python c++ tensorflow
add a comment |
up vote
0
down vote
favorite
The python code runs fine, but the c++ code needs some fixing:
Tensorflow .pb file in c++, opencv, placeholder tensor 'y_true' with dtype float and shape [?,3]
I am having trouble getting the correct formats for c++. I can run the code in python.
One error message I receive in c++ is: You must feed a value for placeholder tensor 'y_true' with dtype float and shape [?,3]
[[Node: y_true = Placeholderdtype=DT_FLOAT, shape=[?,3], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]
The error message is because the result is not returned to the correct size array in c++, but I am having trouble understanding how to fix this.
The code is below: the lines I'm not understanding are where to put y_test_images in the c++ code:
pythyon:
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
c++:
I think I should put t somewhere, but not sure where:
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
This is the line that is not returning the correct result
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
In python the following code works:
sess = tf.Session()
saver = tf.train.import_meta_graph('trained\break_up.meta')
sess.run(tf.global_variables_initializer())
saver.restore(sess, tf.train.latest_checkpoint('trained'))
graph = tf.get_default_graph()
y_pred = graph.get_tensor_by_name("y_pred:0")
x= graph.get_tensor_by_name("x:0")
y_true = graph.get_tensor_by_name("y_true:0")
y_test_images = np.zeros((1, 3))
images2 = np.array(images_tf, dtype=np.uint8)
images2 = images2.astype('float32')
images2 = np.multiply(images2, 1.0/255.0)
x_batch = images2.reshape(1, 32,32,3)
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
print(result[0,0],result[0,1],result[0,2])
I am having trouble with the y_test_images numpy array on the c++ side.
tensorflow::GraphDef graph_def;
std::string graphFile = "break_up2.pb";
tensorflow::Status graphLoadedStatus = ReadBinaryProto(tensorflow::Env::Default(),graphFile,&graph_def);
if (!graphLoadedStatus.ok()){
std::cout << graphLoadedStatus.ToString()<<std::endl;
return 1;
}
int node_count = graph_def.node_size();
for (int i = 0; i < node_count; i++)
{
auto n = graph_def.node(i);
std::cout<<"Names : "<< n.name() <<std::endl;
std::cout<<"OP : "<< n.op() <<std::endl;
}
std::unique_ptr<tensorflow::Session> session_inception(tensorflow::NewSession(tensorflow::SessionOptions()));
tensorflow::Status session_create_status = session_inception->Create(graph_def);
if (!session_create_status.ok()){
std::cout << session_create_status.ToString()<<std::endl;
return 1;
}
std::vector<tensorflow::Tensor> finalOutput;
std::string InputName = "x:0";
std::string OutputName = "y_true:0";
std::vector<float> data_y[3];
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
auto t_matrix = t.matrix<float>();
t_matrix(0, 0) = 1.0;
t_matrix(0, 1) = 0.5;
t_matrix(0, 2) = 0.0;
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
if (!run_status.ok()){
std::cout << run_status.ToString() << "n";
return 1;
}
python c++ tensorflow
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
The python code runs fine, but the c++ code needs some fixing:
Tensorflow .pb file in c++, opencv, placeholder tensor 'y_true' with dtype float and shape [?,3]
I am having trouble getting the correct formats for c++. I can run the code in python.
One error message I receive in c++ is: You must feed a value for placeholder tensor 'y_true' with dtype float and shape [?,3]
[[Node: y_true = Placeholderdtype=DT_FLOAT, shape=[?,3], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]
The error message is because the result is not returned to the correct size array in c++, but I am having trouble understanding how to fix this.
The code is below: the lines I'm not understanding are where to put y_test_images in the c++ code:
pythyon:
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
c++:
I think I should put t somewhere, but not sure where:
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
This is the line that is not returning the correct result
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
In python the following code works:
sess = tf.Session()
saver = tf.train.import_meta_graph('trained\break_up.meta')
sess.run(tf.global_variables_initializer())
saver.restore(sess, tf.train.latest_checkpoint('trained'))
graph = tf.get_default_graph()
y_pred = graph.get_tensor_by_name("y_pred:0")
x= graph.get_tensor_by_name("x:0")
y_true = graph.get_tensor_by_name("y_true:0")
y_test_images = np.zeros((1, 3))
images2 = np.array(images_tf, dtype=np.uint8)
images2 = images2.astype('float32')
images2 = np.multiply(images2, 1.0/255.0)
x_batch = images2.reshape(1, 32,32,3)
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
print(result[0,0],result[0,1],result[0,2])
I am having trouble with the y_test_images numpy array on the c++ side.
tensorflow::GraphDef graph_def;
std::string graphFile = "break_up2.pb";
tensorflow::Status graphLoadedStatus = ReadBinaryProto(tensorflow::Env::Default(),graphFile,&graph_def);
if (!graphLoadedStatus.ok()){
std::cout << graphLoadedStatus.ToString()<<std::endl;
return 1;
}
int node_count = graph_def.node_size();
for (int i = 0; i < node_count; i++)
{
auto n = graph_def.node(i);
std::cout<<"Names : "<< n.name() <<std::endl;
std::cout<<"OP : "<< n.op() <<std::endl;
}
std::unique_ptr<tensorflow::Session> session_inception(tensorflow::NewSession(tensorflow::SessionOptions()));
tensorflow::Status session_create_status = session_inception->Create(graph_def);
if (!session_create_status.ok()){
std::cout << session_create_status.ToString()<<std::endl;
return 1;
}
std::vector<tensorflow::Tensor> finalOutput;
std::string InputName = "x:0";
std::string OutputName = "y_true:0";
std::vector<float> data_y[3];
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
auto t_matrix = t.matrix<float>();
t_matrix(0, 0) = 1.0;
t_matrix(0, 1) = 0.5;
t_matrix(0, 2) = 0.0;
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
if (!run_status.ok()){
std::cout << run_status.ToString() << "n";
return 1;
}
python c++ tensorflow
The python code runs fine, but the c++ code needs some fixing:
Tensorflow .pb file in c++, opencv, placeholder tensor 'y_true' with dtype float and shape [?,3]
I am having trouble getting the correct formats for c++. I can run the code in python.
One error message I receive in c++ is: You must feed a value for placeholder tensor 'y_true' with dtype float and shape [?,3]
[[Node: y_true = Placeholderdtype=DT_FLOAT, shape=[?,3], _device="/job:localhost/replica:0/task:0/device:CPU:0"]]
The error message is because the result is not returned to the correct size array in c++, but I am having trouble understanding how to fix this.
The code is below: the lines I'm not understanding are where to put y_test_images in the c++ code:
pythyon:
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
c++:
I think I should put t somewhere, but not sure where:
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
This is the line that is not returning the correct result
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
In python the following code works:
sess = tf.Session()
saver = tf.train.import_meta_graph('trained\break_up.meta')
sess.run(tf.global_variables_initializer())
saver.restore(sess, tf.train.latest_checkpoint('trained'))
graph = tf.get_default_graph()
y_pred = graph.get_tensor_by_name("y_pred:0")
x= graph.get_tensor_by_name("x:0")
y_true = graph.get_tensor_by_name("y_true:0")
y_test_images = np.zeros((1, 3))
images2 = np.array(images_tf, dtype=np.uint8)
images2 = images2.astype('float32')
images2 = np.multiply(images2, 1.0/255.0)
x_batch = images2.reshape(1, 32,32,3)
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
print(result[0,0],result[0,1],result[0,2])
I am having trouble with the y_test_images numpy array on the c++ side.
tensorflow::GraphDef graph_def;
std::string graphFile = "break_up2.pb";
tensorflow::Status graphLoadedStatus = ReadBinaryProto(tensorflow::Env::Default(),graphFile,&graph_def);
if (!graphLoadedStatus.ok()){
std::cout << graphLoadedStatus.ToString()<<std::endl;
return 1;
}
int node_count = graph_def.node_size();
for (int i = 0; i < node_count; i++)
{
auto n = graph_def.node(i);
std::cout<<"Names : "<< n.name() <<std::endl;
std::cout<<"OP : "<< n.op() <<std::endl;
}
std::unique_ptr<tensorflow::Session> session_inception(tensorflow::NewSession(tensorflow::SessionOptions()));
tensorflow::Status session_create_status = session_inception->Create(graph_def);
if (!session_create_status.ok()){
std::cout << session_create_status.ToString()<<std::endl;
return 1;
}
std::vector<tensorflow::Tensor> finalOutput;
std::string InputName = "x:0";
std::string OutputName = "y_true:0";
std::vector<float> data_y[3];
tensorflow::Tensor t(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, 3}));
auto t_matrix = t.matrix<float>();
t_matrix(0, 0) = 1.0;
t_matrix(0, 1) = 0.5;
t_matrix(0, 2) = 0.0;
tensorflow::Status run_status = session_inception->Run({{InputName,input_tensor}},{{OutputName}},{},&finalOutput);
if (!run_status.ok()){
std::cout << run_status.ToString() << "n";
return 1;
}
python c++ tensorflow
python c++ tensorflow
asked Nov 21 at 5:35
jester
17218
17218
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405805%2ftensorflow-pb-file-in-c-opencv-placeholder-tensor-y-true-with-dtype-float%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown