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

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

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

Can't get attribute 'SPPF' on 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')

你可能感兴趣的:(目标跟踪,深度学习,pytorch)