使用YOLOv5模型训练: 显卡内存不够导致报错RuntimeError: CUDA out of memory

news/2024/10/18 0:32:27/
Logging results to runs\train\exp18
Starting training for 300 epochs...Epoch   gpu_mem       box       obj       cls    labels  img_size0%|          | 0/8 [00:03<?, ?it/s]
Traceback (most recent call last):File "E:\SelfLearning\Pytorch_Learning\yolov5\yolov5-6.0\train.py", line 620, in <module>main(opt)File "E:\SelfLearning\Pytorch_Learning\yolov5\yolov5-6.0\train.py", line 517, in maintrain(opt.hyp, opt, device, callbacks)File "E:\SelfLearning\Pytorch_Learning\yolov5\yolov5-6.0\train.py", line 315, in trainpred = model(imgs)  # forwardFile "D:\DeepLearning\anzhuangCode\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_implreturn forward_call(*input, **kwargs)File "E:\SelfLearning\Pytorch_Learning\yolov5\yolov5-6.0\models\yolo.py", line 126, in forwardreturn self._forward_once(x, profile, visualize)  # single-scale inference, trainFile "E:\SelfLearning\Pytorch_Learning\yolov5\yolov5-6.0\models\yolo.py", line 149, in _forward_oncex = m(x)  # runFile "D:\DeepLearning\anzhuangCode\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_implreturn forward_call(*input, **kwargs)File "E:\SelfLearning\Pytorch_Learning\yolov5\yolov5-6.0\models\common.py", line 45, in forwardreturn self.act(self.bn(self.conv(x)))File "D:\DeepLearning\anzhuangCode\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_implreturn forward_call(*input, **kwargs)File "D:\DeepLearning\anzhuangCode\lib\site-packages\torch\nn\modules\activation.py", line 391, in forwardreturn F.silu(input, inplace=self.inplace)File "D:\DeepLearning\anzhuangCode\lib\site-packages\torch\nn\functional.py", line 2048, in silureturn torch._C._nn.silu(input)
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.66 GiB already allocated; 0 bytes free; 1.72 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF进程已结束,退出代码1

遇到上述情况报错是由于模型batchsize设置的较大导致模型在训练时显卡内存不够。

遇到这种情况可以将batchsize减小。

在终端运行命令将batch修改合适的大小即可:
python train.py --img 640 --batch 4 --epochs 6


http://www.ppmy.cn/news/714177.html

相关文章

显卡内存管理机制及驱动实现(Intel gma500为例)

背景 在Intel Atom芯片的环境中分析故障时&#xff0c;顺便看了下该环境的显卡驱动中的内存管理相关机制&#xff0c;显卡为Atom CPU的集成显卡&#xff0c;低端产品&#xff0c;gma500显卡。本文主要关注该显卡驱动中的内存管理相关的实现原理&#xff0c;其他显卡原理与之类…

计算机显卡内存分布查看,Win10电脑查看显卡内存的详细教程

许多朋友买电脑时都看重电脑显卡大小&#xff0c;有时视频分辨率和显卡是有很大关系&#xff0c;那要想查看Win10电脑显卡内存应该怎么查看呢&#xff1f;详细查看方法如下所示。 方法一 1、鼠标左键点击左下方的Win10图标&#xff0c;弹出下拉菜单&#xff0c;在下拉菜单里找到…

【深度分析】如何配置深度学习用的电脑(显卡和内存的选择标准)

一、显卡指标 位宽 : 一个时钟周期内&#xff0c;显示芯片从显存中读取数据量&#xff0c;单位bit&#xff1b;显存频率&#xff1a;表示1s内显存和显示芯片之间数据传输次数&#xff0c; 单位MHZ&#xff1b;显存带宽&#xff1a;表示1s内显存与显卡芯片之间的的数据传输量&a…

CSS文本溢出显示省略号

1、单行文本溢出显示省略号 overflow: hidden;&#xff08;文字长度超出限定宽度&#xff0c;则隐藏超出的内容&#xff09; white-space: nowrap;&#xff08;设置文字在一行显示&#xff0c;不能换行&#xff09; text-overflow: ellipsis;&#xff08;规定当文本溢出时&…

s3 存储操作命令 与 GitHub CI 集成

s3 存储操作命令 与 GitHub CI 集成 下载安装 Mac本地安装方法&#xff1a; # bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"brew install s3cmds3cmd --version s3cmd version 2.2.0参考链接…

快快网络I9-13900K性能优势

快快网络最新推出的I9-13900K处理器以其出色的性能和卓越的表现在科技界引起了广泛关注。作为一款高性能处理器&#xff0c;它在多个方面都表现出了明显的优势。 高性能处理能力 I9-13900K采用了先进的7纳米制程技术&#xff0c;拥有8核16线程的配置&#xff0c;主频高达5.3G…

JavaScript(JS)的引入方法

内部脚本 JS代码必须位于<script></script>标签之间在HTML文档中&#xff0c;可以在任意地方&#xff0c;放置任意数量的<script>一般会把脚本置于<body>元素的底部&#xff0c;可以改善显示速度 外部脚本&#xff1a;将JS代码定义在外部JS文件中&…

VS Code报错 No module named ‘torch‘ (但已经安装了pytorch)

一、复现错误程序 创建一个python文件 test.py&#xff0c;其内容为&#xff1a; import torch print(torch.__version__)使用VS Code打开并运行该程序时&#xff0c;会出现以下错误&#xff1a; ModuleNotFoundError: No module named ‘torch’ 二、解决方案 选择适合的Pyt…