c++ - tensorflow C++ API : How to read Tensor from files?

标签 c++ tensorflow

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

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++ 示例代码?我在任何地方都找不到它...

最佳答案

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

关于c++ - tensorflow C++ API : How to read Tensor from files?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42688085/

相关文章:

c++ - libstdc++ 私有(private) basic_streambuf 构造函数

c++ - 如何在 Visual C++ 2010 Express 中更改编译器

c++ - 如何在 C++ 中同时拥有 32 位和 64 位 float

tensorflow - TensorFlow 仅限于神经网络吗?

Python Tensorflow NoneType 不可迭代

c++ - 检查我的头文件中的命令行选项

docker - 部署Tensorflow服务客户端脚本

python - 为什么这个简单的 Tensorflow 代码不成功? (使用 Tensorflow 的 ConvnetJS)

python - ImageDataGenerator 是否会向我的数据集添加更多图像?

c++ - 检查 STL 容器中是否已存在值的最快方法