ValueError:层顺序的输入 0 与层不兼容:输入形状的预期轴 -1

时间:2021-02-23 07:46:19

标签: deep-learning conv-neural-network

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 186 but received input with shape (None, 180)

----------------------------------------------< /p>

import IPython.display as ipd
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import librosa
from tqdm import tqdm
from sklearn.preprocessing import StandardScaler
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import Adam

model = Sequential()

model.add(Dense(186, input_shape=(186,), activation = 'relu'))

model.add(Dense(256, activation = 'relu'))
model.add(Dropout(0.6))

model.add(Dense(128, activation = 'relu'))
model.add(Dropout(0.5))

model.add(Dense(10, activation = 'softmax'))

model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')

history = model.fit(X_train, y_train, batch_size=64, epochs=30)

1 个答案:

答案 0 :(得分:0)

您的 X_train 的形状是 (None,180),但您将形状 (None,186) 输入到密集层。 改变

model.add(Dense(186, input_shape=(186,), activation = 'relu'))

到:

model.add(Dense(186, input_shape=(180,), activation = 'relu'))