记录贴 |YOLOv5遇到的问题

报错1

AttributeError: Can’t get attribute ‘SPPF’ on <module ‘models.common’ from ‘F:\PycharmProjects\github\yolov5-5.0\models\common.py’>

解决方法

打开项目-models-common.py,在class SPP前面加入:

class SPPF(nn.Module):
    def __init__(self, c1, c2, k=5):
        super().__init__()
        c_ = c1 // 2
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * 4, c2, 1, 1)
        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
 
    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))
报错2

OSError: [WinError 1455] 页面文件太小,无法完成操作。 Error loading

解决方法

打开项目-utils-datasets.py文件(约81行处):

修改dataloader中的num_workers=0

报错3

RuntimeError: result type Float can‘t be cast to the desired output type __int64

解决方法

打开错误信息中的loss.py文件,最后那段for函数,将其整体替换为yolov5-master版中loss.py最后一段for函数,替换函数如下:

for i in range(self.nl):
            anchors, shape = self.anchors[i], p[i].shape
            gain[2:6] = torch.tensor(shape)[[3, 2, 3, 2]]  # xyxy gain
 
            # Match targets to anchors
            t = targets * gain  # shape(3,n,7)
            if nt:
                # Matches
                r = t[..., 4:6] / anchors[:, None]  # wh ratio
                j = torch.max(r, 1 / r).max(2)[0] < self.hyp['anchor_t']  # compare
                # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t']  # iou(3,n)=wh_iou(anchors(3,2), gwh(n,2))
                t = t[j]  # filter
 
                # Offsets
                gxy = t[:, 2:4]  # grid xy
                gxi = gain[[2, 3]] - gxy  # inverse
                j, k = ((gxy % 1 < g) & (gxy > 1)).T
                l, m = ((gxi % 1 < g) & (gxi > 1)).T
                j = torch.stack((torch.ones_like(j), j, k, l, m))
                t = t.repeat((5, 1, 1))[j]
                offsets = (torch.zeros_like(gxy)[None] + off[:, None])[j]
            else:
                t = targets[0]
                offsets = 0
 
            # Define
            bc, gxy, gwh, a = t.chunk(4, 1)  # (image, class), grid xy, grid wh, anchors
            a, (b, c) = a.long().view(-1), bc.long().T  # anchors, image, class
            gij = (gxy - offsets).long()
            gi, gj = gij.T  # grid indices
 
            # Append
            indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1)))  # image, anchor, grid
            tbox.append(torch.cat((gxy - gij, gwh), 1))  # box
            anch.append(anchors[a])  # anchors
            tcls.append(c)  # class
报错4

NotImplementedError: Could not run ‘torchvision::nms’ with arguments from the ‘CUDA’ backend.

解决方法

版本不匹配/不能调用CUDA
先查看自己的显卡,cuda版本,重新安装cuda,cudnn

当时没有继续报错,第二天又出现此报错!

解决方法

卸载重装torch和torchvision
查看自己的python版本,根据版本下载再安装
下载网址:https://download.pytorch.org/whl/torch_stable.html
下载时应注意如下:

  • cu表示gpu版本,cpu表示cpu版本
  • cu后面的数字表示版本号,cu117表示版本CUDA11.7;
  • torch-后面的数字表示torch版本;
  • cp后面的数字表示python版本,cp39表示python3.9;
  • linux表示linux系统,win_amd64表示windows 64为系统。
#先卸载原来的
pip uninstall torch
pip uninstall torchvision
#把下载的文件移到pytorch环境下
#在pytorch环境下安装新的
pip install torch-1.13.0+cu117-cp39-cp39-win_amd64.whl
pip install torchvision-0.14.0+cu117-cp39-cp39-win_amd64.whl

在这里插入图片描述

#查看是否安装成功,安装成功即可看见torch和torchvision版本号
conda list
#进入python查看是否可以用gpu训练,Ture则表示成功
python
import torch
print(torch.cuda.is_available())

在这里插入图片描述

报错5

Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

解决方法

将NumPy卸载重装,如果重装失败,检查是不是安装目录有重复的包,删除后重新安装即可

pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy
报错6

ImportError: DLL load failed while importing _imaging: 找不到指定的模块。

解决方法

更新Pillow

python -m pip install --upgrade Pillow

在这里插入图片描述

报错7

ImportError: DLL load failed while importing ft2font: 找不到指定的模块

解决方法

把matplotlib换成低版本,进入python环境

python
import matplotlib
print(matplotlib.__version__)#查看当前matplotlib的版本
exit()
pip uninstall matplotlib       
pip install matplotlib==3.3.3

在这里插入图片描述

报错8

LooseVersion = distutils.version.LooseVersion AttributeError: module ‘distutils’ has no attribute ‘version’

解决方法

setuptools版本过高导致,把setuptools换成低版本

pip uninstall setuptools
pip install setuptools==59.5.0 //需要比之前的低 

在这里插入图片描述

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值