weixin_45044307 2020-04-16 18:11 采纳率: 0%
浏览 506

请大佬告知keras lstm输出问题

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层输出后应该怎么做?还是我之前的步骤有问题?

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-29 05:58
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀