YOLOX训练:显存足够,但依旧CUDA out of memory(Tried to allocate 5.58 GiB,8.00 GiB total capacity,6.40 GiB free)

问题已经解决,请参考以下博文:
https://blog.csdn.net/ELSA001/article/details/120918082?spm=1001.2014.3001.5501

刚刚我尝试训练自己的yolox_s模型,但我batch_size不管改成多少,甚至改成1,都直接报CUDA out of memory,我很苦恼,这里明明显示我的显存是足够的,但是依旧OOM。
训练命令如下:

(mypytorch) E:\YOLOX>python tools/train.py -f exps/example/yolox_voc/yolox_voc_s_bm.py -d 1 -b 2 --fp16 -o -c weights/yolox_s.pth

我在这里加载了GitHub的预训练权重文件:yolox_s.pth

报错图片如下:
在这里插入图片描述

RuntimeError: CUDA out of memory. 
Tried to allocate 5.58 GiB (GPU 0; 8.00 GiB total capacity; 
43.62 MiB already allocated; 6.40 GiB free;
8.00 GiB allowed; 64.00 MiB reserved in total by PyTorch)

如果不加载预训练权重文件:
训练命令如下:

(mypytorch) E:\YOLOX>python tools/train.py -f exps/example/yolox_voc/yolox_voc_s_bm.py -d 1 -b 2 --fp16 -o

报错图片如下:

在这里插入图片描述

RuntimeError: CUDA out of memory. 
Tried to allocate 5.66 GiB (GPU 0; 8.00 GiB total capacity; 
43.62 MiB already allocated; 6.40 GiB free; 8.00 GiB allowed; 
64.00 MiB reserved in total by PyTorch)

也是一模一样的报错!
我的显卡是GeForce RTX 3070 Laptop GPU,8G的显存:在这里插入图片描述

我找了很久的解决方案,比如在终端输入nvidia-smi
来查看显存使用情况,但我发现我没有进程占用显存:在这里插入图片描述
我在输入命令时,GPU使用情况是这样的:
在这里插入图片描述

接着,我把训练命令的-o去掉了(我也不知道-o是什么意思,GitHub的YOLOX训练解释好像也没有解释-o是什么意思:https://github.com/Megvii-BaseDetection/YOLOX/blob/main/docs/train_custom_data.md)。
命令如下:

(mypytorch) E:\YOLOX>python tools/train.py -f exps/example/yolox_voc/yolox_voc_s_bm.py -d 1 -b 2 --fp16

在这里插入图片描述
接着,报了这个错误:

RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR
You can try to repro this exception using the following code snippet. If that doesn't trigger the error, please include your original repro script when reporting this issue.

在这里插入图片描述
我去查了一下这个问题的解决方案:
https://blog.csdn.net/flashlau/article/details/120724131
然后我照着这个教程做了:
把这一段代码输入到一个文件:

import torch
torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.benchmark = True
torch.backends.cudnn.deterministic = False
torch.backends.cudnn.allow_tf32 = True
data = torch.randn([2, 12, 320, 320], dtype=torch.half, device='cuda', requires_grad=True)
net = torch.nn.Conv2d(12, 32, kernel_size=[3, 3], padding=[1, 1], stride=[1, 1], dilation=[1, 1], groups=1)
net = net.cuda().half()
out = net(data)
out.backward(torch.randn_like(out))
torch.cuda.synchronize()

在这里插入图片描述
在这里插入图片描述

然后再使用python命令来运行它:

在这里插入图片描述
然后没有一点点输出,我看了下其他的教程,应该也是显存的问题。
这让我真的很难受,我都没想到会这样,希望有同学遇到这个错误的话可以帮我看看嘛,我估计问题比较大,要修改很多东西。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值