为诗人进行TensorFlow训练期间GPU利用率为0%

问题描述 投票:5回答:2

我正在遵循TensorFlow Retraining for Poets的说明。 GPU利用率似乎很低,所以我按照Using GPU中的说明检测了retrain.py脚本。日志验证TF图是否在GPU上构建。我正在接受大量课程和图像的再培训。请帮助我调整TF和the retraining script中的参数以利用GPU。从this question中我知道我应该减小批量大小。这个脚本的“批处理大小”由什么构成并不明显。我有60节课和1MM训练图像。首先制作1MM瓶颈文件。那部分是CPU,速度很慢,我理解这一点。然后以4,000步进行训练,在该步骤中每次拍摄100张图像。这是批次吗?如果减少每步的图像数量,GPU利用率会提高吗?

python tensorflow gpu gpgpu pre-trained-model
2个回答
0
投票

让我们与您的问题一个一个地走:

  1. 批大小是一次对其进行训练/测试/验证的图像数。您可以在脚本中找到相应的参数及其默认值:
  parser.add_argument(
      '--train_batch_size',
      type=int,
      default=100,
      help='How many images to train on at a time.'
  )
  parser.add_argument(
      '--test_batch_size',
      type=int,
      default=-1,
      help="""\
      How many images to test on. This test set is only used once, to evaluate
      the final accuracy of the model after training completes.
      A value of -1 causes the entire test set to be used, which leads to more
      stable results across runs.\
      """
  )
  parser.add_argument(
      '--validation_batch_size',
      type=int,
      default=100,
      help="""\
      How many images to use in an evaluation batch. This validation set is
      used much more often than the test set, and is an early indicator of how
      accurate the model is during training.
      A value of -1 causes the entire validation set to be used, which leads to
      more stable results across training iterations, but may be slower on large
      training sets.\
      """
  )

因此,如果要减小训练批处理的大小,则应使用此参数来运行脚本:

python -m retrain --train_batch_size=16

我还建议您将批处理大小的数字指定为2的幂(16、32、64、128,...)。这个数字取决于您使用的GPU。 GPU的内存越少,您应使用的批处理大小就越小。在GPU中使用8Gb时,您可以尝试批处理大小为16。

  1. 要发现您是否正在使用GPU,请follow the steps in the Tensorflow documentation you mentioned-只需输入tf.debugging.set_log_device_placement(True)

作为脚本的第一条语句

设备放置日志记录将导致打印任何张量分配或操作。


0
投票

我通常会做以下事情。

  1. 检查是否正在使用GPU。

    tf.test.is_gpu_available()

  2. 监控GPU使用率。

    watch -n 0.1 nvidia-smi

  3. 如果您的CPU使用率较低。在[之后写]

    train_batches = train.shuffle(SHUFFLE_BUFFER_SIZE).batch(BATCH_SIZE)

    train_batches = train_batches.prefetch(1)#这将预取一批

  4. 如果您的GPU使用率仍然很低。

  5. batch_size = 128

  6. 如果您的gpu仍然很低。可能是:

  7. ((1)您的图太简单了,无法使用更多gpu。(2)代码错误或程序包错误。

© www.soinside.com 2019 - 2024. All rights reserved.