2016-11-15 51 views
2

我只是絆了這個問題: TensorFlow - Read all examples from a TFRecords at once?Tensorflow:使用tf.parse_example爲JPEG批次

首先回答問題的建議使用tf.parse_example而不是解析單的例子,因爲這似乎是更快。但提供的代碼並不完整,我不知道如何使用它。如果我批處理,然後使用parse_example我會得到一批功能。這意味着我需要解壓該批次才能解碼jpegs?從答案中的代碼是:

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文檔](https://www.tensorflow.org/versions/r0.11/api_docs/python/io_ops.html#decode_raw)它應該解碼整批示例。 – sygi

+1

對不起,我複製了另一個問題的代碼,沒有意識到這是一個不同的小問題。我使用jpegs ...我將編輯這個問題! tf.image.decode_jpeg不支持我認爲的批處理 –

回答

2

我有同樣的問題。我去了關於它的方法是使用TensorFlow,tf.map_fnhigher order operators要具體:

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功能。

相關問題