2017-03-09 10 views
0

いくつかのファイルにトレーニングデータ(多分フロートベクトル)を保存し、Tensorflow C++リーダークラスを使用してTensorとしてロードしようとしました。 ここに私のコードです。Tensorflow C++ API:ファイルから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を示しています。 (以下はシェル上の私のプログラムの実行結果です)

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 ReaderReadまたはclass FIFOQueueのC++サンプルコードはありますか?私はどこにでもそれを見つけることができません...

答えて

0

何をしているのかはグラフを構築することです。このグラフを実行するには、セッションを作成して実行する必要があります。これを行う方法の例については、the label_image example on the tensorflow codebaseを参照してください。

+0

このサンプルコードは非常に役立つようです。ありがとう! –

関連する問題