yolov5训练数据集 用yolov5x.yaml,报错CUDA out of memory.

用指令python train.py --img 640 --batch 16 --epochs 5 --data ./data/voc2020.yaml --cfg ./models/yolov5x.yaml --device 0 --weights ''

报错RuntimeError: CUDA out of memory.Tried to allocate 32.00 MiB (GPU 0; 8.00 GiB total capacity; 5.98 GiB already allocated; 6.06 MiB free; 6.07 GiB reserved in total by PyTorch)

后来将--batch 16 改成--batch 4,将一次给的数据调小后,可以顺利运行,但是运行速度慢。

用的3070显卡,之前用yolov5s.yaml训练的时候,--batch 16没有问题的。

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这篇博客: 调试YOLOv3/YOLOv5过程中遇到的各种问题中的 2. RuntimeError: CUDA out of memory. 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    形如RuntimeError: CUDA out of memory. Tried to allocate 1.04 GiB (GPU 0; 4.00 GiB total capacity; 86.63 MiB already allocated; 2.52 GiB free; 94.00 MiB reserved in total by PyTorch)
    显存不够,调小训练的batch-size,其他进程关掉点或者重启一下电脑


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^