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

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

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

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

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

一、错误1
Can't get attribute 'SPPF' on 
解决方案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
下载到
如图同级目录下就行了,然后就可以运行了!

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

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

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