刚刚我尝试训练自己的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命令来运行它:
 然后没有一点点输出,我看了下其他的教程,应该也是显存的问题。 这让我真的很难受,我都没想到会这样,希望有同学遇到这个错误的话可以帮我看看嘛,我估计问题比较大,要修改很多东西。
|