neural-network - Tensorflow Inception 多 GPU 训练损失未求和?

标签 neural-network tensorflow conv-neural-network

我正在尝试检查多个 GPU(在一台机器上)的 Tensorflow 初始代码。我很困惑,因为据我所知,我们从不同的塔(又名 GPU)中得到了多个损失,但评估的损失变量似乎只是最后一个塔的损失,而不是所有塔的损失的总和塔:

for step in xrange(FLAGS.max_steps):
  start_time = time.time()
  _, loss_value = sess.run([train_op, loss])
  duration = time.time() - start_time

最后专门为每个塔定义loss的位置:

for i in xrange(FLAGS.num_gpus):
  with tf.device('/gpu:%d' % i):
    with tf.name_scope('%s_%d' % (inception.TOWER_NAME, i)) as scope:
      # Force all Variables to reside on the CPU.
      with slim.arg_scope([slim.variables.variable], device='/cpu:0'):
        # Calculate the loss for one tower of the ImageNet model. This
        # function constructs the entire ImageNet model but shares the
        # variables across all towers.
        loss = _tower_loss(images_splits[i], labels_splits[i], num_classes,
                           scope)

有人可以解释一下合并不同塔的损失的步骤在哪里吗?或者我们只是用一个塔的损失来代表另一个塔的损失?

下面是代码链接: https://github.com/tensorflow/models/blob/master/inception/inception/inception_train.py#L336

最佳答案

出于监控目的,考虑到所有塔都按预期工作,单个塔的损耗与所有塔损耗的平均值一样具有代表性。这是因为批处理和分配到的塔之间没有关系。

但是 train_op 使用所有塔的梯度,如 line 263 , 278因此,从技术上讲,培训应考虑所有塔的批处理。

请注意,平均损失的方差将低于单塔损失的方差,但它们将具有相同的期望。

关于neural-network - Tensorflow Inception 多 GPU 训练损失未求和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38546146/

相关文章:

python - 构建一个只有全连接层(而不是卷积层)的残差网络有意义吗?

machine-learning - 神经网络的输入选择

Python神经网络不训练

python - 飞行数据集的准确性非常低

python - TensorFlow 无法将字符串转换为数字

python - 如何在 Keras 中首先通过卷积网络然后通过循环网络传递一对图像?

c++ - 修改多个输入的 Caffe C++ 预测代码

tensorflow - 估计服务 Keras 模型所需的资源

Python:并行化 GPU 和 CPU 工作

python - PyTorch ValueError : Target size (torch. Size([64])) 必须与输入大小相同 (torch.Size([15]))