导出Python TensorFlow模型并将其导入C++

Kyl*_*oN- 5 c++ python neural-network tensorflow

我按照本教程尝试根据自己的需要进行更改.我有一个python文件,我训练模型并保存TensorFlow图和frozen_graph,它应该具有权重和体系结构.我有一个C++文件,我在其中阅读frozen_graph并尝试预测一个例子.

// The session will initialize the outputs
vector<Tensor> outputs;
// Run the session, evaluating our "softmax" operation from the graph
status = session->Run(inputs, {"output_TT"}, {}, &outputs);
int nHits = 0;
int nClasses = 2;
for (vector<Tensor>::iterator it = outputs.begin(); it != outputs.end(); ++it) {
    auto items = it->shaped<float, 2>({nTests, nClasses}); // 2 represent number of class
    for (int i = 0; i < nTests; i++) {
        int arg_max = 0;
        float val_max = items(i, 0);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试检索从预测结果我只得到NaNitems(i, 0)

以下是github上的所有文件:

我是否错误地保存了frozen_graph?我还在命令行上用bazel创建了一个冻结图,但效果相同.我在C++中读错了数据吗?