I am very new to TensorFlow C++ API and trying to just build a very simple graph in Python and load/test it in C++ API. Here is the python code to create the graph:
with tf.Session() as sess:
a = tf.placeholder(tf.float32, shape=[2,2], name='a')
b = tf.placeholder(tf.float32, shape=[2,2], name='b')
c = tf.matmul(a, b, name="c")
sess.run(tf.initialize_all_variables())
tf.train.write_graph(sess.graph_def, 'models/', 'graph.pb', as_text=False)
and here is the C code to load and run the graph:
Tensor a(DT_FLOAT, TensorShape({2,2}));
Tensor b(DT_FLOAT, TensorShape({2,2}));
std::vector<std::pair<string, tensorflow::Tensor>> inputs = {
{ "a", a },
{ "b", b },
};
std::vector<tensorflow::Tensor> outputs;
status = session->Run(inputs, {"c"}, {}, &outputs);
However I get this error message:
./tensorflow/core/framework/tensor.h:500] Check failed: 1 == NumElements() (1 vs. 4)Must have a one element tensor
What could be the problem? I noticed if I define my tensors in he python and C++ as [1,1], it goes through without any problem!