简体   繁体   中英

Tensorflow C++ API: How to read Tensor from files?

I saved my training data (maybe float vectors) in some files, and tried to load it as a Tensor using Tensorflow C++ reader class. Here is my code.

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;

It is compiled very well but the cerr shows always empty Tensor. (below is execution result of my program on 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: >

I don't know why it doesn't work. Or, is there any C++ example code for class ReaderRead or class FIFOQueue ? I cannot find it anywhere...

What you're doing is building a graph. To run this graph you need to create a Session and run it. See the label_image example on the tensorflow codebase for an example of how to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM