使用Yolov7遇到的一些问题的解决方法

1.CUDA内存不足

我在使用yolov7中遇到了一些问题,通过查询相关的资料和网站将其一个一个解决了。首先遇到的第一个问题就是cuda的内存不足,报错内容如下所示:

RuntimeError: CUDA out of memory. Tried to allocate 52.00 MiB (GPU 0; 5.80 GiB total capacity; 4.62 GiB already allocated; 36.38 MiB free; 4.64 GiB reserved in total by PyTorch) If reserved memory is

通过分析它主要有以下三种原因。

应该有三个原因

  • GPU还有其他进程占用显存,导致本进程无法分配到足够的显存
  • 缓存过多,使用torch.cuda.empty_cache()清理缓存
  • 卡不行,换块显存更大的卡

解决办法

1.最直接的解决办法是减小batch_size;

python train_net.py --config-file configs/coco/darknet53.yaml --num-gpus 1

如果使用以上命令,可以在 configs/coco/darknet53.yaml文件下使用ctrl+f搜索batch 将其修改为16,还是报同样错误则修改为8。

2.如果在训练过程遇到这种情况,可以尝试在训练前先释放CUDA内存 nvidia-smi查看GPU使用率,如果使用率不高,就使用torch.cuda.empty_cache()释放内存。

在train_net.py中main下面添加如下代码:

    if hasattr(torch.cuda, 'empty_cache'):
        torch.cuda.empty_cache()

以上方法即可解决。

2.UserWarning

报错内容如下:

/yolov7-1.0/yolov7/modeling/meta_arch/yolov7.py:704: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').

  best_n_mask = (best_n_all // 3) == self.level

报错截图如下所示:

使用Yolov7遇到的一些问题的解决方法

按照要求找到yolov7-1.0/yolov7/modeling/meta_arch/yolov7.py文件的704行

使用Yolov7遇到的一些问题的解决方法

将其修改为如下内容:

best_n_mask=torch.div(best_n_all, 3, rounding_mode='floor')== self.level

再次运行下面命令即可成功。

python train_net.py --config-file configs/coco/darknet53.yaml --num-gpus 1

Original: https://blog.csdn.net/m0_54188335/article/details/126346899
Author: 不聪明的小侦探
Title: 使用Yolov7遇到的一些问题的解决方法

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/786365/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球