TensorFlow 数据匮乏的 GPU

标签 tensorflow tf-slim tensorflow-gpu

我需要帮助优化自定义 TensorFlow 模型。我有一个 40GB 的 ZLIB 压缩 .TFRecords 文件,其中包含我的训练数据。每个样本由两个 384x512x3 的图像和一个 384x512x2 的向量场组成。我正在加载我的数据如下:

    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 的全局步数。 (减缓!)

这是我用于并行阅读器的 TensorBoard 破折号。它始终保持在 99%-100%。
enter image description here

我绘制了一段时间内的 GPU 使用率(每秒百分比)。看起来数据不足,但我不知道如何解决这个问题。我试过增加/减少线程数,但似乎没有什么区别。我正在使用具有 4 个 CPU 和 61GB RAM 的 NVIDIA K80 GPU 进行训练。

GPU Usage

我怎样才能让这列火车更快?

最佳答案

如果您的示例很小,那么使用 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

关于TensorFlow 数据匮乏的 GPU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44598246/

相关文章:

python - 如何将多个图像输入 Keras 特征提取?

model - Tensorflow Slim 恢复模型并预测

带有 is_training True 和 False 的 Tensorflow (tf-slim) 模型

几个时期后的 tensorflow-GPU OOM 问题

python - 加载保存的检查点并预测不会产生与训练中相同的结果

python - 张量维度的大小范围 - tf.range

python - 在Jupyter中找不到Tensorboard作为魔术功能

tensorflow - 使用 tfslim 解码 tfrecord

deep-learning - 无论如何,是否可以将 tensorflow-gpu 与 intel(r) hd graphics 520 一起使用?