[英]Incorrect input to Conv2D in Keras
I am trying to learn using deep learning in python to analyse EEG data. 我正在尝试学习在Python中使用深度学习来分析EEG数据。 Unfortunately, I am also new to python, so have tried to find the simplest tools available. 不幸的是,我也是python的新手,因此尝试寻找可用的最简单的工具。 This has lead me to Keras. 这把我引向了Keras。
More precisely, I am trying to implement the following pipe line: 更准确地说,我正在尝试实现以下管道:
So far, I seem to be stuck around "S1" or "C2". 到目前为止,我似乎仍然停留在“ S1”或“ C2”周围。 The idea so far is: 到目前为止的想法是:
input sections of EEG data (1 x 6000 is what I will use for now) 脑电数据的输入部分(我现在将使用1 x 6000)
run that through 20 1D filters (1x200) 通过20个1D滤镜(1x200)运行
However, the below code gives me the following error: 但是,以下代码给了我以下错误:
model = Sequential()
model.add(Conv1D(input_shape=(1,6000), kernel_size=200,strides=1,
activation='sigmoid',filters=20))
model.add(MaxPooling1D(pool_size=20, strides=10,padding='same'))
model.add(Conv2D(filters=400,kernel_size=(20,30),strides=(1,1),activation='sigmoid'))
Output: 输出:
ValueError: Input 0 is incompatible with layer conv2d_4: expected ndim=4, found ndim=3
I am sure this is trivial mistake, but going through the keras documentation has not made me any wiser. 我敢肯定这是微不足道的错误,但是遍历keras文档并没有使我更明智。
I realize the above skips the "stacking" procedure, but the closest thing I could find to that was Concatenate, and that just complains that I have not given it any inputs. 我意识到上面的代码跳过了“堆叠”过程,但是我能找到的最接近的东西是Concatenate,只是抱怨我没有给它任何输入。
I am using theano 0.9.0.dev and keras 2.0.2 我正在使用theano 0.9.0.dev和keras 2.0.2
You need to reshape your data before going from 1D to 2D. 从1D到2D之前,您需要重塑数据。 There is dedicated layer in Keras. Keras中有专用层 。 I guess, your model may start like this: 我想,您的模型可能会像这样开始:
model = Sequential()
model.add(Conv1D(input_shape=(6000,1),kernel_size=200,strides=1,
activation='sigmoid',filters=20))
model.add(MaxPooling1D(pool_size=20, strides=10,padding='same'))
model.add(Reshape((-1, 581, 20)))
model.add(Conv2D(filters=400,kernel_size=(20,30),strides=(1,1),
activation='sigmoid'))
I've also replaced input_shape
to default dimension ordering. 我也将input_shape
替换为默认的尺寸顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.