【问题标题】:Tensorflow C++ API: How to read Tensor from files?Tensorflow C++ API:如何从文件中读取张量?
【发布时间】:2017-03-09 06:16:59
【问题描述】:

我将训练数据(可能是浮点向量)保存在一些文件中,并尝试使用 Tensorflow C++ 阅读器类将其加载为张量。 这是我的代码。

using namespace tensorflow;
using namespace tensorflow::ops;
using namespace tensorflow::sparse;

Scope root = Scope::NewRootScope();

auto indexReader = FixedLengthRecordReader(root, sizeof(uint32_t));
auto queue = FIFOQueue(root, {DataType::DT_STRING});

auto file = Input::Initializer(std::string("mydata.feat"));
std::cerr << file.tensor.DebugString() << std::endl;

auto enqueue = QueueEnqueue(root, queue, {file});
std::cerr << Input(QueueSize(root, queue).size).tensor().DebugString() << std::endl;

auto rawInputIndex = ReaderRead(root, indexReader, queue);
std::cerr << Input(rawInputIndex.key).tensor().DebugString() << std::endl;

auto decodedInputIndex = DecodeRaw(root, rawInputIndex.value, DataType::DT_UINT8);
std::cerr << Input(decodedInputIndex.output).tensor().DebugString() << std::endl;

它编译得很好,但是 cerr 总是显示为空的 Tensor。 (下面是我的程序在shell上的执行结果)

Tensor<type: string shape: [] values: mydata.feat>
Tensor<type: float shape: [0] values: >
Tensor<type: float shape: [0] values: >
Tensor<type: float shape: [0] values: >

我不知道为什么它不起作用。 或者,是否有 class ReaderReadclass FIFOQueue 的 C++ 示例代码?我在任何地方都找不到它...

【问题讨论】:

    标签: c++ tensorflow


    【解决方案1】:

    您正在做的是构建图表。要运行此图,您需要创建一个 Session 并运行它。有关如何执行此操作的示例,请参阅 the label_image example on the tensorflow codebase

    【讨论】:

      猜你喜欢
      • 2019-02-02
      • 2021-11-05
      • 2015-07-15
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多