解决:RuntimeError: CUDA out of memory. Tried to allocate 2.00 MiB
生活随笔
收集整理的這篇文章主要介紹了
解决:RuntimeError: CUDA out of memory. Tried to allocate 2.00 MiB
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
方法一:
僅需減小batchsize
改文件的配置cfg的batchsize=4,一般在cfg文件下的查找batch或batchsize,將batchsize調小后,再次運行,類似于改下面
方法二 :?
上述方法還沒解決,不改batchsize,可以考慮下面的方法的鏈接
不計算梯度:
ps: 在報錯的哪一行代碼的上面,加上下面一行代碼,不計算梯度
with torch.no_grad()
不計算梯度的方法
方法三:
釋放內存:鏈接如下
釋放內存
if hasattr(torch.cuda, 'empty_cache'):torch.cuda.empty_cache()ps: 在報錯的哪一行代碼的上面,加上下面兩行代碼,釋放無關的內存
if hasattr(torch.cuda, 'empty_cache'):torch.cuda.empty_cache()總結
以上是生活随笔為你收集整理的解决:RuntimeError: CUDA out of memory. Tried to allocate 2.00 MiB的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: model.parameters(),m
- 下一篇: yolov4的全面详解