出现错误“资源耗尽:在使用形状 [1800,1024,28,28] 分配张量并在 /job:localhost/... 上键入 float 时出现 OOM”

Thi*_*hru 3 out-of-memory object-detection tensorflow object-detection-api tensorflow2.0

在开始训练我的对象检测 Tensorflow 2.5 GPU 模型时,我收到资源耗尽错误。我使用 18 个训练图像和 3 个测试图像。我使用的预训练模型是 Tensorflow Zoo 2.2 中的 Faster R-CNN ResNet101 V1 640x640 模型。我使用具有 8 GB 专用内存的 Nvidia RTX 2070 来训练我的模型。

我感到困惑的是,当训练集如此之小时,为什么训练过程会占用 GPU 如此多的内存。这是我遇到的错误的 GPU 内存摘要:

Limit:                      6269894656
InUse:                      6103403264
MaxInUse:                   6154866944
NumAllocs:                        4276
MaxAllocSize:               5786902272
Reserved:                            0
PeakReserved:                        0
LargestFreeBlock:                    0
Run Code Online (Sandbox Code Playgroud)

我还将训练数据的批量大小减少到 6,将测试数据的批量大小减少到 1。

Leo*_*ons 5

我在所有在 GPU 上运行的笔记本中使用下面的代码,以防止出现此类错误:

    import tensorflow as tf

    gpus = tf.config.list_physical_devices('GPU')
    if gpus:
      try:
        # Currently, memory growth needs to be the same across GPUs
        for gpu in gpus:
          tf.config.experimental.set_memory_growth(gpu, True)
        logical_gpus = tf.config.list_logical_devices('GPU')
        print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
      except RuntimeError as e:
        # Memory growth must be set before GPUs have been initialized
        print(e)
Run Code Online (Sandbox Code Playgroud)

默认情况下,TensorFlow 映射进程可见的所有 GPU(受 CUDA_VISIBLE_DEVICES 限制)的几乎所有 GPU 内存。

有关将 GPU 与张量流结合使用的更多信息,请参见此处

也许它会解决错误

我希望我对你有帮助