ValueError:输入0与层conv1d_1不兼容:预期ndim = 3,找到的ndim = 4。无法解决错误

时间:2019-07-07 12:31:55

标签: machine-learning conv-neural-network audio-processing

我正在尝试创建一个神经网络,以对音频进行恒定Q变换(均匀长度)进行训练,但遇到上述错误

根据创建的数据集定义参数形状

X_train.shape = (10664, 96, 87, 1)
X_test.shape = (2666, 96, 87, 1)
X_validate.shape = (2666, 96, 87, 1)
Y_train.shape = (10664,)
Y_test.shape = (2666,)
Y_validate.shape = (2666,)

img_rows, img_cols = X_train.shape[1], X_train.shape[2]
input_shape = (img_rows, img_cols, 1)

model = Sequential()

model.add(Conv1D(filters = filters_1, kernel_size = kernel_1, padding='valid', activation='relu', input_shape = input_shape))
model.add(MaxPooling1D(pool_size = 4))
model.add(Conv1D(filters = filters_2, kernel_size = kernel_1, padding='valid', activation='relu'))
model.add(MaxPooling1D(pool_size = 4))
model.add(Conv1D(filters = filters_3, kernel_size = kernel_1, padding='valid', activation='relu'))
model.add(MaxPooling1D(pool_size = 2))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(2048, activation = 'relu'))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adam(), metrics=['accuracy'])

model.summary()

0 个答案:

没有答案