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

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

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

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

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

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

Can't get attribute 'SPPF' on 

解决方案:将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-masterdataimagesbus.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:cbpytorch_1000000000000workatensrcATennativeTensorShape.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')。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1029518.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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