weixin_47245869 2024-09-29 18:24 采纳率: 0%
浏览 3

复现seaformer,出现错误:conv2d() received an invalid combination of arguments

哪位大神能帮我看一下吗? 在复现seaformer做分割任务的时候遇到问题(mvcc=2.0.1,mmegine=0.10.5,mmsegmentation=1.2.2),报错为:TypeError: conv2d() received an invalid combination of arguments - got (list, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:

  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
TypeError: conv2d() received an invalid combination of arguments - got (list, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:
 * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
      didn't match because some of the arguments have invalid types: (list of [Tensor, Tensor, Tensor, Tensor], Parameter, NoneType, tuple of (int, int), tuple of (int, int), tuple of (int, int), int)
 * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
      didn't match because some of the arguments have invalid types: (list of [Tensor, Tensor, Tensor, Tensor], Parameter, NoneType, tuple of (int, int), tuple of (int, int), tuple of (int, int), int)


出错的地方在这里:

class StackedMV2Block(nn.Module):
    def __init__(
            self,
            cfgs,
            stem,
            inp_channel=16,
            activation=nn.ReLU,
            norm_cfg=dict(type='BN', requires_grad=True),
            width_mult=1.):
        super().__init__()
        self.stem = stem
        if stem:
            self.stem_block = nn.Sequential(
                Conv2d_BN(3, inp_channel, 3, 2, 1, norm_cfg=norm_cfg),
                activation()
            )
        self.cfgs = cfgs

        self.layers = []
        for i, (k, t, c, s) in enumerate(cfgs):
            output_channel = _make_divisible(c * width_mult, 8)
            exp_size = t * inp_channel
            exp_size = _make_divisible(exp_size * width_mult, 8)
            layer_name = 'layer{}'.format(i + 1)
            layer = InvertedResidual(inp_channel, output_channel, ks=k, stride=s, expand_ratio=t, norm_cfg=norm_cfg,
                                     activations=activation)
            self.add_module(layer_name, layer)
            inp_channel = output_channel
            self.layers.append(layer_name)

    def forward(self, x):
        print(f"Input type: {type(x)}")
        for tensor in x:
            print(tensor.shape)

        if self.stem:
            x = self.stem_block(x)
        for i, layer_name in enumerate(self.layers):
            layer = getattr(self, layer_name)
            x = layer(x)
        return x

前向传播这里传进去的是个列表,不知道是不是新版本mmseg对数据处理做了改变的原因,打印输出结果为:

img


这优化真的是一坨,升级这个包,那个不能用,降低版本这个又不能用,改了几天,真的是心累@小馨馨的小翟 @旋转的油纸伞 @高斯小哥 @tangjunjun-owen

  • 写回答

1条回答 默认 最新

  • 一轮明月照丘壑 2024-09-29 18:29
    关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    看起来你在使用PyTorch的conv2d()函数时遇到了问题。根据你提供的错误信息,问题似乎在于你正在尝试将一个列表作为输入传递给conv2d()函数,但它期望的是一个张量(Tensor)。你的输入数据是一个列表,这可能就是你遇到问题的原因。此外,从你提供的代码中,我看不到你实际如何使用conv2d()函数,所以可能还有其他的因素导致这个问题。你需要确保你正确地使用了这个函数。

    在PyTorch中,conv2d()函数通常用于在卷积层之间传递张量数据。它接受以下参数:输入张量(input)、权重张量(weight)、偏置张量(bias)、步长(stride)、填充(padding)、膨胀(dilation)和组数(groups)。你的错误信息指出,你可能尝试用一个列表代替了这些参数中的某一个或几个。你需要检查你的代码,确保你传递给conv2d()函数的参数是正确的类型。

    关于你的代码,我注意到你在StackedMV2Block类的forward方法中处理的是一个列表x,而这个列表包含的是张量。这可能是你遇到问题的原因。你需要确保你正确处理了这个列表,例如,选择一个合适的张量作为conv2d()的输入。这可能涉及到选择一个合适的张量从列表中取出,或者可能需要将列表中的每个张量单独处理。如何解决这个问题取决于你的具体需求和数据的结构。如果你不确定怎么做,你可以提供更多的信息,我会尽力帮助你解决问题。

    此外,如果你使用的是mmsegmentation库进行语义分割任务,你需要确保你的输入数据符合该库的要求。例如,你可能需要将图像转换为适当的格式和尺寸,并使用适当的预处理步骤。你可能需要查阅mmsegmentation的文档以获取更多关于如何正确使用该库的信息。

    评论

报告相同问题?

问题事件

  • 创建了问题 9月29日

悬赏问题

  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见
  • ¥15 一共有五道问题关于整数幂的运算还有房间号码 还有网络密码的解答?(语言-python)
  • ¥20 sentry如何捕获上传Android ndk 崩溃
  • ¥15 在做logistic回归模型限制性立方条图时候,不能出完整图的困难
  • ¥15 G0系列单片机HAL库中景园gc9307液晶驱动芯片无法使用硬件SPI+DMA驱动,如何解决?