我正在尝试复制example on Keras's website:
# as the first layer in a Sequential model
model = Sequential()
model.add(LSTM(32, input_shape=(10, 64)))
# now model.output_shape == (None, 32)
# note: `None` is the batch dimension.
# for subsequent layers, no need to specify the input size:
model.add(LSTM(16))
但是当我运行以下内容时:
# only lines I've added:
from keras.models import Sequential
from keras.layers import Dense, LSTM
# all else is the same:
model = Sequential()
model.add(LSTM(32, input_shape=(10, 64)))
model.add(LSTM(16))
但是,我得到以下内容:
ValueError: Input 0 is incompatible with layer lstm_4: expected ndim=3, found ndim=2
版本:
Keras: '2.0.5'
Python: '3.4.3'
Tensorflow: '1.2.1'
答案 0 :(得分:2)
LSTM
图层作为默认选项必须仅返回序列的最后一个输出。这就是为什么你的数据失去其顺序性质的原因。为了改变这种尝试:
model.add(LSTM(32, input_shape=(10, 64), return_sequences=True))
是什么让LSTM
返回整个预测序列。