2017-06-16 111 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上。 –