使用GPU训练yolo_v2报错:RuntimeError: CUDA out of memory. Tried to allocate XXX MiB

报错内容:
RuntimeError: CUDA out of memory. Tried to allocate 200.00 MiB (GPU 0; 8.00 GiB total capacity; 5.96 GiB already allocated; 0 bytes free; 6.18 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

这个报错的意思就是:
运行时错误:CUDA内存不足。尝试分配200.00个MiB(GPU 0;8.00 GiB总容量;5.96 GiB已分配;0字节空闲;PyTorch总共保留6.18 GiB)如果保留内存>>已分配内存,请尝试设置最大拆分大小以避免碎片。

错误原因:
显卡内存不够,因为显卡内存不够大的话,当batch_size过大,那么处理的数据量就过大,训练时模型的所有参数都会参与计算,数据内存就会溢出,显卡内存就不够用了。

解决办法:
训练时候,将batch_size 改小点,例如:
python train.py --cuda --batch_size 64 --num_workers 0
改为:
python train.py --cuda --batch_size 2 --num_workers 0

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值