解决pytorch tets时显存不够的问题:CUDA out of memory. Tried to allocate 114.00 MiB

今天在运行一项图像refocus的程序时遇到了CUDA out of memory. Tried to allocate 114.00 MiB的问题,判断是显存不够的问题,于是记录以下解决的方法:
(1)单卡改多卡,这次还是报错,而且有新的错误:RuntimeError: Caught RuntimeError in replica 0 on device 0.
该问题的解决方法可以参考:
https://blog.csdn.net/liu_yuan_kai/article/details/109290375?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&dist_request_id=1331996.9521.16188988554774151&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
https://blog.csdn.net/senius/article/details/96599955?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
(2)还是使用单卡,最终是通过在报错的那一行前面加上:

if hasattr(torch.cuda, 'empty_cache'):
	torch.cuda.empty_cache()

并且在test之前添加:

with torch.no_grad():
  # test process

详情可参考:
https://my.oschina.net/u/4294880/blog/4478375

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值