1
我對TensorFlow C++ API非常新穎,試圖在Python中構建一個非常簡單的圖形,並在C++ API中加載/測試它。這裏是Python代碼來創建圖表:Tensorflow C++,張量問題和餵食問題
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)
,這裏是C代碼加載和運行圖:
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);
不過,我收到此錯誤信息:
./tensorflow/core/framework/tensor.h:500]檢查失敗:1 == NumElements()(1對4)必須有一個單元張量
可能是什麼問題?我注意到如果我在python和C++中定義我的張量爲[1,1],它就會毫無問題地經過!