2017-07-19 201 views
2

为什么下面的代码给出ValueError: Input 0 is incompatible with layer dense_14: expected min_ndim=2, found ndim=1?当我删除unroll=True时,它是有效的,我不希望这会影响LSTM的输出维度。展开时Keras不兼容的输入尺寸LSTM

from keras.models import Sequential 
from keras.layers import LSTM, Dense 
model = Sequential() 
model.add(LSTM(
    100, 
    batch_input_shape=(1, 1, 17), 
    unroll=True 
)) 
model.add(Dense(1)) 

我想这与此有关:

In [9]: from keras.models import Sequential 
    ...: from keras.layers import LSTM, Dense 
    ...: from keras import backend as K 
    ...: def LSTM_output_dimensions(*args,**kwargs): 
    ...: model = Sequential() 
    ...: model.add(LSTM(
    ...:  *args, 
    ...:  **kwargs 
    ...: )) 
    ...: return K.ndim(model.outputs[0]) 
    ...: 

In [10]: LSTM_output_dimensions(50, batch_input_shape=(1, 1, 17)) 
Out[10]: 2 

In [11]: LSTM_output_dimensions(50, batch_input_shape=(1, 1, 17),return_sequences=True) 
Out[11]: 3 

In [12]: LSTM_output_dimensions(50, batch_input_shape=(1, 1, 17),unroll=True) 
Out[12]: 1 

In [13]: LSTM_output_dimensions(50, batch_input_shape=(1, 1, 17),unroll=True,return_sequences=True) 
Out[13]: 2 
+0

您使用哪种'Keras'版本? –

+0

Python 2.7上的keras 2.0.5 – tba

回答

0

这似乎是发生是因为unroll=True是不相关的(1, x)输入形状的bug in Keras