2016-06-27 6 views
2

私はTensorflow/python APIを使用して画像をポーズにマッピングする回帰ネットワークを実装しており、FixedLengthRecordReaderの出力を処理しようとしています。スライシングTensorflow FixedLengthRecordReader値

私はcifar10 exampleを私の目的に合わせて最小限にしようとしています。

cifar10の例では、生のバイトを読み取り、デコードしてから分割します。

result.key, value = reader.read(filename_queue) 

# Convert from a string to a vector of uint8 that is record_bytes long. 
record_bytes = tf.decode_raw(value, tf.uint8) 

# The first bytes represent the label, which we convert from uint8->int32. 
result.label = tf.cast(
    tf.slice(record_bytes, [0], [label_bytes]), tf.int32) 

# The remaining bytes after the label represent the image, which we reshape 
# from [depth * height * width] to [depth, height, width]. 
depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]), 
         [result.depth, result.height, result.width]) 
# Convert from [depth, height, width] to [height, width, depth]. 
result.uint8image = tf.transpose(depth_major, [1, 2, 0]) 

私は(pose_data、image_data)として保存されたデータを持つバイナリファイルのリストから読んでいます。私のポーズデータはfloat32であり、画像データはuint8なので、まずスライスしてからキャストしたいと思います。残念ながら、reader.readの値の結果は0次元のテンソルのテンソルであるため、スライスは機能しません。

key, value = reader.read(filename_queue) 
print value.dtype 
print value.get_shape() 

<dtype: 'string'> 
() 

tf.decode_raw(値、DTYPE)の結果は、1次元配列であるが、指定するDTYPEを必要とし、tf.stringは、それが取る有効なタイプではありません。

デコードする前にスライスすることはできますか?または、私はデコードする必要がありますか?>大文字小文字の逆順 - >スライス - >再作成?全く別の方法がありますか?

答えて

0
OPだけでなく、あなたのデータは複数のタイプ(OPの質問に)持っているときは動作しません。二回のデコードで溶液が言及した

cifar10例との因子であることがn_uint8_valsが必要です(より一般的な場合) '整列しない'。

あなたのデータは、例えばある場合:

[float32][int16][int16] 

二回デコード作品。しかし、あなたのデータが:

[int16][float32][int16] 

の場合は、tf.decode_rawは半分のfloat32のオフセットを受け入れないので、動作しません。

何このケースで作業を行うこと

result.key, value = reader.read(filename_queue) 

からの戻り値が実際に文字列(またはバイト文字列あなたがする場合)で、tf.substr()

自体が分裂しましょう。

-1

解決策が見つかりました:2回デコードして半分を取り除きます。それほど効率的ではない(誰かがより良い解決策を持っているなら、それを聞いてうれしいだろう)が、うまくいくようだ。

key, value = reader.read(filename_queue) 
uint8_bytes = tf.decode_raw(value, tf.uint8) 
uint8_data = uint8_bytes[:n_uint8_vals] 
float32_bytes = tf.decode_raw(value, tf.float32) 
float32_start_index = n_uint8_vals // 4 
float32_data = float32_bytes[float32_start_index:] 

これは4

+0

リンクが壊れている場合は、ここに貼り付けることができる場合は例を参照してください。 – Bastiaan

関連する問題