model = Sequential() model.add(LSTM(units=32, input_shape=(sequence_length, 4))) model.add(Dropout(0.2)) model.add(LSTM(units=32)) model.add(Dense(units=1, activation='sigmoid')) 报错model.add(LSTM(units=32)) ValueError: Input 0 of layer "lstm_8" is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 32)
时间: 2024-01-24 11:16:45 浏览: 132
LSTM_keras.zip_LSTM_LSTM;keras_keras_keras lstm_lstm keras
这个错误是因为在添加第二个LSTM层之前,您需要在第一个LSTM层中设置`return_sequences=True`参数,以便将输出作为输入传递给第二个LSTM层。
请尝试以下代码:
```
model = Sequential()
model.add(LSTM(units=32, input_shape=(sequence_length, 4), return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=32))
model.add(Dense(units=1, activation='sigmoid'))
```
这应该会解决您遇到的错误。
阅读全文