首页 > 解决方案 > 输出一个 3 形状的 LSTM

问题描述

我试图了解 LSTM 的基础知识并构建了这个模型:

self.model = Sequential()

self.model.add(LSTM(self.config.layers[0],
    input_shape=(None, channel.X_train.shape[2]),
    return_sequences=True))
    self.model.add(Dropout(self.config.dropout))

self.model.add(LSTM(
    self.config.layers[1],
    return_sequences=True))
self.model.add(Dropout(self.config.dropout))

self.model.add(Dense(
self.config.n_predictions))
self.model.add(Activation('linear'))

输入形状是 (2000, 200, 10),我需要一个相同形状的输出。我尝试过这种方式,但我得到了错误:

ValueError: Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=2

如果我将第二层的 return_sequence 参数设置为False,它会起作用,但我会得到形状 (X, Y) 的输出,这不是我想要的。

标签: pythondeep-learninglstmshapes

解决方案


推荐阅读