keras 1D卷积输入形状

时间:2017-08-02 21:07:08

标签: tensorflow keras conv-neural-network convolution

我正在尝试为1D卷积创建模型,但我似乎无法使输入形状正确。这就是我所拥有的:

#this is actually shape (6826, 9000) but I am shortening it
train_dataset_x = np.array([[0, 1, 5, 1, 10], [0, 2, 4, 1, 3]])
#this is actually shape (6826, 1)
train_dataset_y = np.array([[0], [1]])

model.add(Conv1D(32, 11, padding='valid', activation='relu', strides=1, input_shape=( len(train_dataset_x[0]), train_dataset_x.shape[1]) ))
model.add(Conv1D(32, 3, padding='valid', activation='relu', strides=1) )
model.add(MaxPooling1D())

model.add(Conv1D(64, 3, padding='valid', activation='relu', strides=1) )
model.add(Conv1D(64, 3, padding='valid', activation='relu', strides=1) )
model.add(MaxPooling1D())


model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

我收到此错误:

ValueError: Error when checking input: expected conv1d_1_input to have 3 dimensions, but got array with shape (6826, 9000)

有人有建议吗?

1 个答案:

答案 0 :(得分:3)

keras.layers.Conv1D的输入应为3维,尺寸为(nb_of_examples, timesteps, features)。我假设您有一个长度为6000且具有1个特征的序列。在这种情况下:

X = X.reshape((-1, 9000, 1))

应该做的工作。