ip = Input(shape=(1,10))
op = BatchNormalization()(ip)
print(ip.shape)
op = LSTM(10, return_sequences=True, dropout=0.1, #input_shape=(1, 193),
recurrent_dropout=0.2)(op)
print(op.shape)
op = Flatten()(op)
out = Dense(5,activation='softmax')(op)
model = Model(ip,out)
model.summary()
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
x = train_x1
kfold = StratifiedKFold(n_splits=10, shuffle=True)
x = x.reshape(-1,1,10)
cvscores = []
for train, test in kfold.split(x, y):
print(x[train].shape,x[test].shape)
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
history = model.fit(x[train], y[train], epochs=300, batch_size=128)
scores = model.evaluate(x[test], y[test], verbose=0)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
cvscores.append(scores[1] * 100)
Layer (type) Output Shape Param #
input_22 (InputLayer) (None, 1, 10) 0
batch_normalization_9 (Batch (None, 1, 10) 40
lstm_16 (LSTM) (None, 1, 10) 840
flatten_5 (Flatten) (None, 10) 0
dense_23 (Dense) (None, 5) 55
Total params: 935
Trainable params: 915
Non-trainable params: 20
我这是个语音模型,输入数据是几百条语音,每条语音有10个压缩特征。我reshape成(-1,1,10)输入到lstm里面,但是最后想做一个5分类。但是总报错
ValueError: Error when checking target: expected dense_23 to have shape (5,) but got array with shape (1,)
求问大佬这个lstm层输出后应该怎么做?还是我之前的步骤有问题?