私は、事前に訓練されたモデルを読み込んで使用するC++プログラムを構築しようとしています。私はコードfrom hereをとり、少し修正しました。 私が今持っていることは次のとおりです。なぜ "dtype int64でプレースホルダテンソルの出力に '値を入力する必要がありますか?
int main(int argc, char* argv[]) {
// Initialize a tensorflow session
Session* session;
Status status = NewSession(SessionOptions(), &session);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
// Read in the protobuf graph we exported
GraphDef graph_def;
status = ReadTextProto(Env::Default(), "models/train.pbtxt", &graph_def);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
// Add the graph to the session
status = session->Create(graph_def);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
tensorflow::Tensor inputs(DT_FLOAT, TensorShape({46}));
auto inputs_flat = inputs.flat<float>();
inputs_flat.setRandom();
// The session will initialize the outputs
std::vector<tensorflow::Tensor> outputs;
status = session->Run({{"input", inputs}}, {"output"}, {}, &outputs);
if (!status.ok()) {
std::cout << status.ToString() << "\n"; // <--- error shows here
return 1;
}
// Grab the first output
// and convert the node to a scalar representation.
auto output_c = outputs[0].scalar<int>();
// Print the results
std::cout << outputs[0].DebugString() << "\n";
std::cout << output_c() << "\n";
// Free any resources used by the session
session->Close();
return 0;
}
しかし、私はそれを実行したとき、私は私がmodels/train.pbtxt
で読んでいるグラフは、14Kラインを持っているので、私はここでそれをコピーしていないです
Invalid argument: You must feed a value for placeholder tensor 'output' with dtype int64
[[Node: output = Placeholder[_output_shapes=[[-1]], dtype=DT_INT64, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
を取得します。
このようなエラーメッセージはどういう意味ですか?
このテンソルフローライブラリは、出力変数が 'Run'呼び出しの出力ノードに渡されることを期待していますか? – tinkertime
たぶん、どうですか?私が見た例はこのようなものです。ここに別のものがあります:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/public – matiasg