yolov5编译过程中遇到的问题

1.Can’t get attribute ‘SPPF’ on <module ‘models.common’ from ‘D:\develop\yolo\yolov5-hat\models\common.py’>

在编译detect.py文件时遇到这个问题,在使用yolov5s.pt中,可以发现在common.py中缺少SPPF模块,应该是由于版本问题。解决方法如下:
找到common.py文件,添加下面代码,添加之后导入import warnings这个模块

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.The size of tensor a (80) must match the size of tensor b (56) at non-singleton dimension 3

这是由于下载的yolov5s.pt版本不一样导致的,默认下载的是tag6.1的yolov5s.pt,我们需要重新下载tag5的yolov5s.pt进行提换,下载链接如下:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
替换之后就能够运行了
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

慕溪同学

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

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

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

打赏作者

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

抵扣说明:

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

余额充值