【发布时间】:2018-02-28 08:18:13
【问题描述】:
我正在尝试为我的数据集构建卷积神经网络。我的训练数据集有 1209 个样本,每个样本有 800 个特征。
下面是部分代码的样子:
model = Sequential()
model.add(Conv1D(64, 3, activation='linear', input_shape=(1209, 800)))
model.add(GlobalMaxPooling1D())
model.add(Dense(1, activation='linear'))
model.compile(loss=loss_type, optimizer=optimizer_type, metrics=[metrics_type])
model.fit(X, Y, validation_data=(X2,Y2),epochs = nb_epochs,
batch_size = batch_size,shuffle=True)
当我编译这段代码时,我得到以下错误:
Error when checking input: expected conv1d_25_input to have 3 dimensions,
but got array with shape (1209, 800)
所以我添加了一个维度,这就是我要做的:
X = np.expand_dims(X, axis=0)
X2 = np.expand_dims(X2, axis=0)
然后我得到这个错误:
ValueError: Input arrays should have the same number of samples as target arrays.
Found 1 input samples and 1209 target samples.
我的训练数据现在是这样的形状(1、1209、800),应该是别的吗?
非常感谢您阅读本文。
【问题讨论】:
-
你的
Y.shape是什么? -
@MarcinMożejko 它是 (1209,1),因为我在数据集中有 1209 个示例,每个示例只有一个输出。我尝试用 Y = np.expand_dims(Y, axis=0) Y2 = np.expand_dims(Y2, axis=0) 改变它,但遗憾的是它没有帮助
标签: python-3.x keras conv-neural-network keras-layer