我现在在 Windows 中使用 pytorch 0.4.0 来构建 CNN,这是我的代码:
class net(nn.Module):
def __init__(self):
super(net, self).__init__()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=16, kernel_size=(1,3),stride=1 )
self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=(1,3), stride=1)
self.dense1 = nn.Linear(32 * 28 * 24, 60)
self.out = nn.Linear(60,3)
def forward(self, input):
x = F.relu(self.conv1(input))
x = F.relu(self.conv2(x))
x = x.view(x.size(0), -1) # flatten(batch,32*7*7)
x = self.dense1(x)
output = self.out(x)
return output
但我得到的错误是
File "D:\Anaconda\lib\site-packages\torch\nn\modules\conv.py", line 301, in forward
self.padding, self.dilation, self.groups)
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]
我认为这表明我在上面的代码中犯了一些错误,但我不知道如何修复它,任何人都可以帮助我吗?提前致谢!