Tensorflow:多 GPU 单输入队列

Tensorflow: Multi-GPU single input queue

tensorflow's cifar10 multi-GPU example 中,似乎(如果我错了请纠正我)每个 GPU 创建一个训练图像队列。 "right" 做事的方式难道不是让一个队列为所有塔提供服务吗?如果是这样,是否有可用的共享队列示例?

你是正确的,CIFAR-10 模型的代码使用多个输入队列(通过 cifar10.tower_loss() 多次调用 cifar10.distorted_inputs())。

在 GPU 之间使用共享队列的最简单方法是执行以下操作:

  1. 将批量大小增加 N 倍,其中 N 是 GPU 的数量。

  2. 将对 cifar10.distorted_inputs() 的调用从 cifar10.tower_loss() 移到 loop over GPUs 之外。

  3. 沿第 0(批次)维度拆分从 cifar10.distorted_inputs() 返回的 imageslabels 张量:

    images, labels = cifar10.distorted_inputs()
    split_images = tf.split(0, FLAGS.num_gpus, images)
    split_labels = tf.split(0, FLAGS.num_gpus, labels)
    
  4. 修改cifar10.tower_loss()以获取imageslabels参数,并按如下方式调用它:

    for i in xrange(FLAGS.num_gpus):
      with tf.device('/gpu:%d' % i):
        with tf.name_scope('%s_%d' % (cifar10.TOWER_NAME, i)) as scope:
    
          loss = tower_loss(scope, split_images[i], split_labels[i])