keras 1D卷积输入形状 [英] keras 1D convolution input shape
本文介绍了keras 1D卷积输入形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为1D卷积创建模型,但似乎无法正确输入形状.这是我所拥有的:
I am trying to create a model for 1D convolution, but I cant seem to get the input shape correct. Here is what I have:
#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)
有人有建议吗?
推荐答案
对 keras.layers.Conv1D
的输入应为3维,尺寸为(nb_of_examples,时间步长,特征)代码>.我假设您有一个长度为
6000
且具有1个功能的序列.在这种情况下:
Input to keras.layers.Conv1D
should be 3-d with dimensions (nb_of_examples, timesteps, features)
. I assume that you have a sequence of length 6000
with 1 feature. In this case:
X = X.reshape((-1, 9000, 1))
应该做这项工作.
这篇关于keras 1D卷积输入形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文