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