我有以下两个变量:
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)
出:
torch.Size([16, 1, 28, 28])
等效于:
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])
填充默认为0,步幅默认为1。第一个示例中的最后两个维度与第二个示例中的内核大小相对应。
kernel_size=5
与相同kernel_size=(5,5)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句