2016-11-15 8 views
2

のjpegバッチのtf.parse_example: TensorFlow - Read all examples from a TFRecords at once?Tensorflow:使用私はちょうどこの質問つまずい

そして、最初の答えはtf.parse_exampleを使用しての代わりに、それがより速くなるように思われるので、単一の例を解析示唆しています。しかし、提供されたコードは完全ではなく、どのように使用できるのか分かりません。バッチしてparse_exampleを使うと、バッチの機能が得られます。つまり、jpegを解読するためにそのバッチを解凍する必要がありますか?答えからのコードは次のとおりです。

reader = tf.TFRecordReader() 
_, serialized_example = reader.read(filename_queue) 
features = tf.parse_single_example(serialized_example, features={ 
     image/center': tf.VarLenFeature(tf.string), 
    }) 
image = features['image/center'] 
image_decoded = tf.image.decode_jpeg(image.values[0], channels=3) 
return image_decoded 

とに切り替えることをお勧め:

batch = tf.train.batch([serialized_example], num_examples, capacity=num_examples) 
parsed_examples = tf.parse_example(batch, feature_spec) 

しかし、どのように、私は今、それらのparsed_examplesをデコードすることができますか?

+0

そのまま実行するとどうなりますか? [tf.decode_raw documentation](https://www.tensorflow.org/versions/r0.11/api_docs/python/io_ops.html#decode_raw)によれば、バッチ全体のサンプルをデコードする必要があります。 – sygi

+1

ああ申し訳ありませんが、私は他の質問からそのコードをコピーしました。私はjpegsを使用します...私は質問を編集します! tf.image.decode_jpegは私が考えるバッチをサポートしていません –

答えて

2

私は同じ問題を抱えていました。

batch = tf.train.batch([serialized_example], num_examples, capacity=num_examples) 

parsed_examples = tf.parse_example(batch, 
    features={ 
     'image_jpg': tf.FixedLenFeature([], tf.string), 
    }) 

raw_bytes_batch = parsed_examples['image_jpg'] 

def decode(raw_bytes): 
    return tf.image.decode_jpeg(raw_bytes, channels=3) 

image_decoded = tf.map_fn(decode, raw_bytes_batch, dtype=tf.uint8, 
          back_prop=False, parallel_iterations=10) 
# image_decoded.set_shape([None, ..., ..., 3]) 

これは、並行してJPEGファイルにdecode機能を実行する必要があります。私はそれについていった方法は、具体的にはTensorFlow、tf.map_fnhigher order operatorsを使用することです。

関連する問題