2017-08-05 54 views
1

我试图复制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

我的回答对你有帮助吗? –

回答

1

LSTM图层作为其默认选项必须仅返回序列中的最后一个输出。这就是为什么你的数据失去了序列性。为了改变这种尝试:

model.add(LSTM(32, input_shape=(10, 64), return_sequences=True)) 

是什么让LSTM返回预测的整个序列。