2017-06-16 184 views
3

我需要優化自定義TensorFlow模型的幫助。我有一個包含我的訓練數據的40GB ZLIB壓縮.TFRecords文件。每個樣本由兩個384x512x3圖像和一個384x512x2矢量場組成。我加載我的數據如下:TensorFlow Data Starved GPU

num_threads = 16 
    reader_kwargs = {'options': tf.python_io.TFRecordOptions(tf.python_io.TFRecordCompressionType.ZLIB)} 
    data_provider = slim.dataset_data_provider.DatasetDataProvider(
         dataset, 
         num_readers=num_threads, 
         reader_kwargs=reader_kwargs) 
    image_a, image_b, flow = data_provider.get(['image_a', 'image_b', 'flow']) 

    image_as, image_bs, flows = tf.train.batch(
     [image_a, image_b, flow], 
     batch_size=dataset_config['BATCH_SIZE'], # 8 
     capacity=dataset_config['BATCH_SIZE'] * 10, 
     num_threads=num_threads, 
     allow_smaller_final_batch=False) 

不過,我只得到約0.25至0.30的全球步/秒。 (SLOW!)

這是我平行讀者的TensorBoard破折號。一直在99%-100%。 enter image description here

我繪我的GPU使用一段時間(每秒%)。它看起來數據匱乏,但我不知道如何解決這個問題。我試過增加/減少線程的數量,但它似乎沒有什麼區別。我正在使用4個CPU和61GB內存的NVIDIA K80 GPU進行培訓。

GPU Usage

我怎樣才能讓這列火車更快?

回答

0

如果你的例子很小,那麼使用DataSetProvider不會導致滿意的結果。它一次只能讀一個例子,這可能是一個瓶頸。我已經添加了一個feature request on github

在此期間,你必須與使用read_up_to自己的輸入隊列卷:

batch_size = 10000 
    num_tfrecords_at_once = 1024 
    reader = tf.TFRecordReader() 
    # Here's where the magic happens: 
    _, records = reader.read_up_to(filename_queue, num_tfrecords_at_once) 

    # Batch records with 'enqueue_many=True' 
    batch_serialized_example = tf.train.shuffle_batch(
     [records], 
     num_threads=num_threads, 
     batch_size=batch_size, 
     capacity=10 * batch_size, 
     min_after_dequeue=2 * batch_size, 
     enqueue_many=True) 

    parsed = tf.parse_example(
     batch_serialized_example, 
     features=whatever_features_you_have) 
    # Use parsed['feature_name'] etc. below 
+0

感謝您的建議!我繼續前進,嘗試它,沒有任何區別。每個TFRecord都相當大(兩個384x512x3 float32和一個384x512x2 float32),所以我認爲我沒有遇到同樣的問題。 –

+0

對,這個尺寸的記錄可能沒有什麼區別。在配料之前是否進行任何預處理?在CPU上修復所有這些操作可能是有意義的,以防止自動佈局器將某些操作放在其他設備上,這可能會導致不必要的複製。 – panmari

+0

我正在做* *之後的預處理*,顯式地在CPU上。 –