簡體   English   中英

Tensorflow:用C ++打印張量的內容

[英]Tensorflow: Print contents of a tensor in C++

如何打印到下面定義的張量的屏幕內容

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

並通過運行以下操作賦值

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

例如

// 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

打印d維張量流:: Tensor T

#define printTensor(T, d) \
    std::cout<< (T).tensor<float, (d)>() << std::endl

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM