【问题标题】:TF2 Object Detection - Custom training failed (OOM) after successful training in the pastTF2 对象检测 - 过去成功训练后自定义训练失败 (OOM)
【发布时间】:2021-04-04 15:00:24
【问题描述】:

我基于 TF2 Object Detection Effectivedet _d2_coco17_tpu-32 中的预训练模型训练了一个对象检测模型。 https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md

我根据此过程的需要更改了 pipeline.config(我之前在 eff_d1 或 tf2 对象检测动物园的 ssd 模型上做过很多次)。

我成功地在批量大小 2 和 10K 步上训练了这个模型。 但是,当尝试以 100K 步/50K 步/20K 步进行训练时,我遇到了 00M 错误。

我不明白为什么会发生这种情况。

GPU 培训 - Nvidia GeForce RTX 3070 Ubuntu 20.04 TF 2.4.1

任何想法, 谢谢

【问题讨论】:

    标签: python-3.x tensorflow ubuntu tensorflow2.0 object-detection-api


    【解决方案1】:

    我不知道你在训练期间做了什么。我给出原因。 如果增加批量大小,则会发生 oom 错误。您需要检查您的 GPU 是否正在运行任何其他不需要的进程。使用以下命令并结束不需要的进程。

    nvidia-smi
    

    在少数情况下,图像大小会导致内存不足问题,更高的分辨率使用更高的内存。图片尺寸计算

    64×64 and batch of 32
    
    the memory cost on GPU is:
    
    32⋅32⋅3
    (size of the image if in color)⋅32(size of batch)⋅32(bits for a float32) bits ≈3MB
    

    你可以使用这个标志来避免OOM错误

    TF_FORCE_GPU_ALLOW_GROWTH=true

    第一个选项:

    下面这段代码对应TF2.0的第一个选项。

    config = tf.ConfigProto()
    config.gpu_options.allow_growth=True
    sess = tf.Session(config=config)
    

    第二个选项:

    下面这段代码对应TF2.0的第二个选项,但它设置的是内存分数,不是一个确定的值。

    # change the memory fraction as you want...import tensorflow as tf
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)
    sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
    

    如果您看到 shuffle 分配,您可以在 pipeline.config 中根据您的 GPU 定义 shuffle 图像分配,有时可能会导致 OOM 错误。

    【讨论】:

    • 感谢您的回答,但遗憾的是它对我没有帮助。我以前都做过,没用。
    猜你喜欢
    • 1970-01-01
    • 2020-02-20
    • 2014-06-22
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 2018-12-07
    相关资源
    最近更新 更多