先粘贴一段official guide:nn.conv1d官方
我一开始被in_channels、out_channels卡住了很久,结果发现就和conv2d是一毛一样的。话不多说,先粘代码(菜鸡的自我修养)
class CNN1d(nn.Module):
51 def __init__(self):
52 super(CNN1d,self).__init__()
53 self.layer1 = nn.Sequential(
54 nn.Conv1d(1,100,2),
55 nn.BatchNorm1d(100),
56 nn.ReLU(),
57 nn.MaxPool1d(8))
58 self.layer2 = nn.Sequential(
59 nn.Conv1d(100,50,2),
60 nn.BatchNorm1d(50),
61 nn.ReLU(),
62 nn.MaxPool1d(8))
63 self.fc = nn.Linear(300,6)
64 def forward(self,x):
65 #input.shape:(16,1,425)
66 out = self.layer1(x)
70 out = out.view(o