Pytorch 带权重的Py2D

Pytorch 带权重的Py2D,pytorch,conv-neural-network,convolution,Pytorch,Conv Neural Network,Convolution,我有两个变量: result- tensor 1 X 251 X 20 kernel - tensor 1 X 10 X 10 当我运行命令时: from torch.nn import functional as F result = F.conv2d(result, kernel) 我得到一个错误: RuntimeError: expected stride to be a single integer value or a list of 1 values to match the c

我有两个变量:

result- tensor 1 X 251 X 20
kernel - tensor 1 X 10 X 10
当我运行命令时:

from torch.nn import functional as F
result = F.conv2d(result, kernel)
我得到一个错误:

RuntimeError: expected stride to be a single integer value or a list of 1 values to match the convolution dimensions, but got stride=[1, 1]
我没有迈出任何步伐,我做错了什么

import torch
import torch.nn.functional as F
image = torch.rand(16, 3, 32, 32)
filter = torch.rand(1, 3, 5, 5)
out_feat_F = F.conv2d(image, filter,stride=1, padding=0)
print(out_feat_F.shape)
输出:

这相当于:

import torch
import torch.nn
image = torch.rand(16, 3, 32, 32)
conv_filter = torch.nn.Conv2d(in_channels=3, out_channels=1, kernel_size=5, stride=1, padding=0)
output_feature = conv_filter(image)
print(output_feature.shape)
输出:

填充默认为0,步幅默认为1。 第一个示例中的过滤器最后两个维度对应于 第二个示例中的内核大小


kernel\u size=5
kernel\u size=(5,5)
相同

Conv2d表示4D数据(B*C*H*W)和4D内核权重。你的似乎是错的。我将数据大小固定为1 X 1 X 251 X 20,但仍然会出现步幅错误。看起来它与重量有关,而不是与数据有关。数据和重量需要有4个维度。对于权重,它类似于(输入通道、输出通道、h、w)
import torch
import torch.nn
image = torch.rand(16, 3, 32, 32)
conv_filter = torch.nn.Conv2d(in_channels=3, out_channels=1, kernel_size=5, stride=1, padding=0)
output_feature = conv_filter(image)
print(output_feature.shape)
torch.Size([16, 1, 28, 28])