目标检测 YOLOv5代码调试相关问题

目标检测 YOLOv5代码调试相关问题

本文基于yolov5的5.0版本。
错误1 Tag5.0中models/common.py文件缺少SPPF类

Can't get attribute 'SPPF' on <module 'models.common' from 'D:\\Pycharm\\Code\\yolov5-5.0\\models\\common.py'>

解决方案:将Tag6.1版本中models/common.py里的SPPF类拷贝过来,同时会提醒缺少一个warnings包,按照提示引入即可。具体SPPF代码可以去github上拷贝,地址https://github.com/ultralytics/yolov5/tree/v6.1/models
下面直接给出SPPF类源代码


```python
class SPPF(nn.Module):
    # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
    def __init__(self, c1, c2, k=5):  # equivalent to SPP(k=(5, 9, 13))
        super().__init__()
        c_ = c1 // 2  # hidden channels
        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')  # suppress torch 1.9.0 max_pool2d() warning
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

错误2 版本不一致

RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton

第一个错误解决以后就出现了这个问题,因为在运行detect.py文件时,yolov5s.pt文件,默认下载的是
Tag6.1版本的。这里去github上下载对应5.0版本的yolov5s.pt即可,链接地址https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt

错误3 图片找不到

AssertionError: Image Not Found D:\pycharm程序\yolov5-master\data\images\bus.jpg(yolov5报错)

错误原因为测试图片文件夹data/images中包含中文路径,把路径全部修改成英文即可。

错误4 function.py

UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:2228.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]

找到function.py文件,将 return _VF.meshgrid(tensors, **kwargs)改为 return _VF.meshgrid(tensors, **kwargs,indexing='ij')

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想学摄影的IT男

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值