c++ - Tensorflow:在 C++ 中打印张量的内容

标签 c++ tensorflow

如何打印到如下定义的张量的屏幕内容

std::vector<tensorflow::Tensor> finalOutput;

并通过运行以下操作为其赋值

tensorflow::Status run_status = session->Run({{"x",input_tensor}, 
                                                       {"keep_prob", keep_prob}},
                                                      {"prediction"},
                                                      {},
                                                  &finalOutput);

最佳答案

对于 example :

// The session will initialize the outputs
std::vector<tensorflow::Tensor> outputs;

// Run the session, evaluating our "c" operation from the graph
status = session->Run(inputs, {"c"}, {}, &outputs);
if (!status.ok()) {
  std::cout << status.ToString() << "\n";
  return 1;
}

// Grab the first output (we only evaluated one graph node: "c")
// and convert the node to a scalar representation.
auto output_c = outputs[0].scalar<float>();

// (There are similar methods for vectors and matrices here:
// https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/public/tensor.h)

// Print the results
std::cout << outputs[0].DebugString() << "\n"; // Tensor<type: float shape: [] values: 30>
std::cout << output_c() << "\n"; // 30

关于c++ - Tensorflow:在 C++ 中打印张量的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45115028/

相关文章:

python - 在 tensorflow 中正确设置学习率的指数衰减

python - 更新 tensorflow 中的张量切片

python - 如何限制 Keras 中权重的格式

c++ - 如何对 C++ 数组进行值初始化?

c++ - 从构造函数调用虚函数和纯虚函数

c++ - 遍历字符串 vector ,从控制台获取输入,给出段错误

javascript - tensorflowjs 加载重新训练的 coco-ssd 模型 - 在浏览器中不起作用

python - keras 模型中损失函数的奇怪行为,具有预训练的卷积基

c++ - 为什么一元运算符返回的类型与其操作数不同?

c++ - 使用参数优化编译器