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

yolov7在检测的时候报RuntimeError: CUDA out of memory. Tried to allocate

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

yolov7在检测的时候报RuntimeError: CUDA out of memory. Tried to allocate

    在训练时,这个问题很常见,只需要确保cudnn 和 torch 正常的情况下,修改batch-size即可解决。但在检测中,特别时检测一段时间后出现RuntimeError: CUDA out of memory. Tried to allocate xx MiB (GPU 0; xx GiB total capacity; xx GiB already allocated; xx MiB free; xx 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_CON
    该问题如果直接用他本身的检测类detect.py时无问题,在自己封装过程的检测类,比如结合deepsort时封装的检测器会报这样的问题。本身检测类在最后用了 with torch.no_grad(): ,该代码作用是放在里面的代码块不计算梯度。在自己封装的类里面加入torch.set_grad_enabled(False),如果自己封装类没有引入torch ,需要import torch,如果开启torch.set_grad_enabled(True),关闭计算梯度的功能,检测一段时间后就不回出现显存溢出的情况。`
    import torch 
    torch.set_grad_enabled(False) #不计算梯度 防止显存运行一段时间后溢出`
    ![detect.py](https://img-blog.csdnimg.cn/aa112bab88984ef7b1e9fe06695f6c46.png)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1030015.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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