这真杀了我。为什么说输入数组是(50,1)却是(50,629,160)?最初我以为Conv1D层给我带来了麻烦,但看来它在输入层中,对吧?
# keras.__version__ = 2.2.4
# X_train.shape = (50,629,160), X_train[0].shape = (629,160)
# y_train.shape = (50,)
dim = X_train[0].shape
input1 = Input(shape=dim,name='input_1')
conv1 = Conv1D(filters=32, kernel_size=2, strides=1, activation='relu', name='conv1', input_shape=dim)(input1)
maxpool1 = MaxPool1D(pool_size=2, name='maxpool1')(conv1)
conv2 = Conv1D(filters=64, kernel_size=2, strides=1, activation='relu', name='conv2')(maxpool1)
maxpool2 = MaxPool1D(pool_size=2, name='maxpool2')(conv2)
conv3 = Conv1D(filters=128, kernel_size=2, strides=1, activation='relu', name='conv3')(maxpool2)
maxpool3 = MaxPool1D(pool_size=2, name='maxpool3')(conv3)
flat1 = Flatten(name='flat1')(maxpool3)
dense1 = Dense(256, activation='relu', name='dense1')(flat1)
dense2 = Dense(128, activation='relu', name='dense2')(dense1)
output1 = Dense(1, activation='sigmoid', name='output')(dense2)
model = Model(inputs=input1,outputs=output1)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(x=X_train,y=y_train, epochs=30, validation_split=0.1, batch_size=32)
和错误代码:
Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (50, 1)