TypeError: conv2d() received an invalid combination of arguments - got (int, Parameter, Parameter,

TypeError: conv2d() received an invalid combination of arguments - got (int, Parameter, Parameter, 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: (!int!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, 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: (!int!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)

遇到了这个问题,找了好久的问题,最后发现是我犯蠢了,我在类型转换之后,输入的还是原来的图片,崩溃,两个小时。。。。。

解决方法:格式转换

模型中输入的图片格式应该是Tensor类型:

    image = Image.open('./images/0.png')
    image = image.convert("L") #变灰度图像,不然channel的值可能大于1
    image = image.resize((28,28)) #修改尺寸
    #image.show()
    print(image.size)
    transf = transforms.ToTensor()
    tensor = transf(image)  #转换成tensor格式
    print(tensor.shape)
    tensor = tensor.type(torch.FloatTensor)
    tensor = tensor.reshape((1, 1, 28, 28)) #我的模型里的训练数据就是(1, 1, 28, 28)
    print(tensor.shape) #最后直接将tensor传入模型即可

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The `conv2d()` function is a convolutional layer in deep learning frameworks like TensorFlow and PyTorch. It takes a few arguments, including the input tensor, the filter (kernel) tensor, the stride, padding, and activation function. If you received an error message saying that `conv2d()` received an invalid combination of arguments, it means that you passed in one or more arguments that are not compatible with each other. Here are a few common reasons why this might happen: - Incorrect input shape: The input tensor must have a certain shape that depends on the framework and the specific convolutional layer you're using. For example, in TensorFlow, the input tensor should have shape `(batch_size, height, width, channels)`. If you pass in an input tensor with a different shape, you may get an error. - Incompatible filter shape: The filter tensor must have a certain shape that depends on the number of filters, filter size, and number of input channels. If you pass in a filter tensor with an incompatible shape, you may get an error. - Incorrect stride or padding: The stride and padding parameters must be chosen carefully to ensure that the output tensor has the desired shape. If you choose stride or padding values that are incompatible with the input or filter shape, you may get an error. - Incorrect activation function: Some convolutional layers require an activation function to be specified, while others do not. If you specify an activation function that is not compatible with the layer, you may get an error. To fix the error, you should carefully check the input, filter, stride, padding, and activation function parameters to ensure that they are compatible with each other and with the specific convolutional layer you're using.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值