Traceback (most recent call last): File "E:/Pycharm_project/MNIST_two_input/test/save_image_feature.py", line 105, in <module> image = model(image) File "E:\Pycharm_project\MNIST_two_input\test\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "E:/Pycharm_project/MNIST_two_input/test/save_image_feature.py", line 61, in forward x = self.conv1(x) File "E:\Pycharm_project\MNIST_two_input\test\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "E:\Pycharm_project\MNIST_two_input\test\venv\lib\site-packages\torch\nn\modules\conv.py", line 463, in forward return self._conv_forward(input, self.weight, self.bias) File "E:\Pycharm_project\MNIST_two_input\test\venv\lib\site-packages\torch\nn\modules\conv.py", line 459, in _conv_forward return F.conv2d(input, weight, bias, self.stride, TypeError: conv2d() received an invalid combination of arguments - got (numpy.ndarray, 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: (!numpy.ndarray!, !Parameter!, !Parameter!, !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: (!numpy.ndarray!, !Parameter!, !Parameter!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (int, int)!, int) 如何解决
时间: 2024-04-22 21:25:42 浏览: 179
这个错误是由于`conv2d()`函数的参数类型不正确导致的。该函数需要接收`Tensor`类型的输入,但是你传递了`numpy.ndarray`类型的输入。
要解决这个问题,你可以将输入数据转换为`Tensor`类型。你可以使用`torch.from_numpy()`函数将`numpy.ndarray`转换为`Tensor`。
具体来说,你可以将以下代码:
```python
image = model(image)
```
修改为:
```python
image = model(torch.from_numpy(image))
```
这样就可以将`numpy.ndarray`类型的输入转换为`Tensor`类型,然后传递给`conv2d()`函数。这样就能够解决这个错误了。
阅读全文