栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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命令来运行它:


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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/344641.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号