I have a 500x2000 matrix, where each row represents an individual and each column is a measurement of some particular quality about that individual.
(我有一个500x2000的矩阵,其中每一行代表一个个体,每一列代表对该个体的某些特定质量的度量。)
I'm using a batch size of 64, so the input for each cycle of the network is actually a 64x2000 matrix. (我使用的批处理大小为64,因此网络每个周期的输入实际上是64x2000矩阵。)
I'm trying to build a CNN in PyTorch to classify individuals given a set of these measurements. (我正在尝试在PyTorch中构建CNN,以便根据一组这些度量对个人进行分类。)
However, I've stumbled on the parameters for the convolutional layer. (但是,我偶然发现了卷积层的参数。)
Below is my current definition for a simple convolutional neural network.
(以下是我对简单卷积神经网络的当前定义。)
class CNNnet(nn.Module)
def __init__(self):
self.conv1 = nn.Conv1d(2000, 200, (1,2), stride=10)
self.pool = nn.MaxPool1d(kernel_size = (1, 2), stride = 2)
self.fc1 = nn.Linear(64, 30)
self.fc2 = nn.Linear(30, 7)
def forward(self, x):
x = x.view(64, 2000, 1)
x = F.relu(self.conv1(x))
x = self.pool(x)
x = F.relu(self.fc1(x))
x = self.fc2(x)
return x
Attempting to train this model produces the following error:
(尝试训练此模型会产生以下错误:)
"RuntimeError: Expected 4-dimensional input for 4-dimensional weight 200 2000 1 2, but got 3-dimensional input of size [64, 2000, 1] instead".
(“ RuntimeError:4维权重为200 2000 1 2的预期4维输入,但尺寸为[64,2000,1]的3维输入”。)
I'm confused on why it's expecting a 4D 200x2000x1x2 matrix (shouldn't the number of output channels be irrelevant to the input? And why is there a 2 at the end?).
(我对为什么期望使用4D 200x2000x1x2矩阵感到困惑(输出通道的数量与输入无关吗?为什么末尾有2?)。)
My question is what would be the proper syntax or approach for writing a CNN (specifically the convolutional layer) when dealing with 1D data.
(我的问题是在处理一维数据时编写CNN(特别是卷积层)的正确语法或方法是什么?)
Any help is greatly appreciated. (任何帮助是极大的赞赏。)
ask by AldehydeDeva translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…