【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b

【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b ,第1张

这里写自定义目录标题
  • 一、错误1
    • 解决方案1
  • 二、 错误2
    • 解决方案2:

一、错误1
Can't get attribute 'SPPF' on models.common' from 'D:\\Pycharm\\Code\\yolov5-5.0\\models\\common.py'>
解决方案1

你可以去github上,这儿我用的是YOLOv5.5的版本,就去Tags6里面的model/common.py里面去找到这个SPPF的类,把它拷过来到你这个Tags5的model/common.py里面,这样你的代码就也有这个类了,还要引入一个warnings包就行了


点开common.py文件

import warnings
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
解决方案2:


注意看这两个是否对应:

因为我运行代码的是后模型没有下载下来,所以自己去github上下载的模型,然后出错了,就是模型错了,这儿给出地址:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
下载到
如图同级目录下就行了,然后就可以运行了!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/719113.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存