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

这篇具有很好参考价值的文章主要介绍了【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、错误1

Can't get attribute 'SPPF' on <module '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包就行了

【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton,python,pytorch
点开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:

【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton,python,pytorch
注意看这两个是否对应:
【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton,python,pytorch
因为我运行代码的是后模型没有下载下来,所以自己去github上下载的模型,然后出错了,就是模型错了,这儿给出地址:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
下载到【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton,python,pytorch
如图同级目录下就行了,然后就可以运行了!文章来源地址https://www.toymoban.com/news/detail-601100.html

到了这里,关于【解决问题】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • DataLoader问题解决:RuntimeError: stack expects each tensor to be equal size, but got [3, 200, 200]entry1

            最近,在数据集处理并载入DataLoader进行训练的时候出现了问题:         我看了一下,大意就是维度也就是通道数不匹配,所以我觉得应该是数据集图片出现了问题。以下是我的普通数据集处理代码:           我一张一张图片放入DataLoader,然后按顺序一张一张的

    2023年04月25日
    浏览(28)
  • 成功解决RuntimeError: batch2 must be a 3D tensor

    成功解决RuntimeError: batch2 must be a 3D tensor。 在深度学习的世界中,张量是构建一切的核心。它们是数据的容器,是模型训练的基石。然而,当我们尝试使用 torch.bmm() 函数进行批量矩阵乘法时,可能会遇到一个常见的错误:“RuntimeError: batch2 must be a 3D tensor”。这个错误提示似乎

    2024年02月22日
    浏览(28)
  • RuntimeError: Given groups=1, weight of size [14, 464, 1, 1], expected input问题解决

    BUG解决 :RuntimeError: Given groups=1, weight of size [14, 464, 1, 1], expected input[16, 116, 56, 1] to have 464 channels, but got 116 channels instead 首选说一下这个问题,这个问题提示想要得到的是464个通道数但是实际上得到的是116个通道。 例如我给某个深度学习网络中加CBAM注意力集中机制,具体可参

    2023年04月08日
    浏览(28)
  • RuntimeError: mat1 dim 1 must match mat2 dim 0 解决方法

    RuntimeError: mat1 dim 1 must match mat2 dim 0 这个错误的大概意思是:矩阵mat1 的第二维度要与mat2的第一维度不匹配 在新增别的数据集进行训练时报当前错误,原因是输入的图像大小与之前不一样,这是新手在学习时常会遇到的问题。 先看报错信息,确定报错位置 我的这个代码是

    2024年02月15日
    浏览(60)
  • error: (-209:Sizes of input arguments do not match) The operation is neither ‘array op array‘ (where

    作者:非妃是公主 专栏:《计算机视觉》 个性签:顺境不惰,逆境不馁,以心制境,万事可成。——曾国藩 Cannot find reference ‘imread‘ in ‘ init .py‘ error: (-209:Sizes of input arguments do not match) The operation is neither ‘array op array‘ (where cs231n-2022-01 Assignments1-numpy的使用 ModuleNotFound

    2024年02月11日
    浏览(41)
  • 【解决】RuntimeError: Boolean value of Tensor with more than one value is ambiguous

    在用pytorch进行损失函数计算时,报错误: 翻译过来就是说: 具有多个值的张量的布尔值不明确  我是这报错: 啥意思?,你问我,我也不知道呀!、、、  错误原因分析: 其实是,因为我损失函数调用时没有初始化,所以导致报错 其实我是初始化了,但是因为没有+(),

    2024年02月16日
    浏览(34)
  • RuntimeError: stack expects each tensor to be equal size ??

    RuntimeError: stack expects each tensor to be equal size, but got [1200, 1200, 3] at entry 0 and [1200, 1344, 3] at entry 1 pytorch 数据处理错误, 网上的各种方法都试过了 1: 检查过数据的输入通道是3, 标签是1,但是输入的大小尺寸不同 2: 进行如下方法也不行!! :3: bs=1,不报错,bs1 报错 4: bug 未解

    2024年02月01日
    浏览(23)
  • 成功解决使用BCEWithLogitsLoss时ValueError: Target size (torch.Size([4])) must be the same as input size (to

    成功解决使用BCEWithLogitsLoss时ValueError: Target size (torch.Size([4])) must be the same as input size (torch.Size([4, 1])) 🌈 个人主页:高斯小哥 🔥 高质量专栏:Matplotlib之旅:零基础精通数据可视化、Python基础【高质量合集】、PyTorch零基础入门教程👈 希望得到您的订阅和支持~ 💡 创作高质量

    2024年03月11日
    浏览(60)
  • 【报错处理】RuntimeError: input.size(-1) must be equal to input_size. Expected 5, got 21

    1、 原因 : 使用view时维度指定错误,LSTM(input,(h0,c0)) 指定batch_first=True​后,input就是(batch_size,seq_len,input_size)否则为input(seq_len, batch, input_size) 2、原因:并不是rnn的错误,而是因为下一函数的输入和这一层输出维度不一样,对照维度信息和尺寸信息修改即可。 推荐报错解决方

    2024年02月16日
    浏览(30)
  • RuntimeError: stack expects each tensor to be equal size, but got at entry

    参考链接:​​​​​​解决Pytorch dataloader时报错每个tensor维度不一样的问题_python_脚本之家 记录一下自己遇到的bug: 问题描述:  问题分析: torch.stack(batch, 0, out=out)出错,原因可能是: 同一个batch的数据图片的维度(H, W, C)要相同(可以见官方文档:其shape必须一致) 问

    2024年02月15日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包