赞
踩
论坛下载了Yolo的改进模型,运行代码开始报错:
RuntimeError: CUDA out of memory. Tried to allocate 2.00 MiB (GPU 0; 4.00 GiB total capacity; 3.49 GiB already allocated; 0 bytes free; 3.50 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
网上有以下解决方案:
改小batchsize数值,一般情况下设置为8,运行没有问题的话可以适当增加,一般为2的整数倍。
添加消除梯度代码,减少运算内存
- import torch,gc
- del variables
- gc.collect()
- torch.cuda.empty_cache()
报错代码上方添加以上内容,手动清理内存
如果以上方法都未能解决这个问题,可以尝试使用较小的网络模型,例如原本使用yolov5l的模型可以适当减小,使用yolov5m或者s的模型,这样可以极大的减小运算量。改进模型中,有些不是特别必要的层级运算可以减少,释放内存。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。