I have a problem with the connection between convolution layer and lstm layer. The data is of shape(75,5) where there is 75 timesteps x 5 data points for each time step. What I want to do is do a convolution on (75x5), get new convolved (75x5) data and feed that data into lstm layer. However, it does not work because the shape of output of convolution layer has number of filters which I do not need. And therefore the shape of convolution layer output is (1,75,5) and input needed for lstm layer is (75,5). How do I just take the first filter.
model = Sequential()
model.add(Convolution2D(1, 5,5,border_mode='same',input_shape=(1,75, 5)))
model.add(Activation('relu'))
model.add(LSTM(75, return_sequences=False, input_shape=(75, 5)))
model.add(Dropout(0.5))
model.add(Dense(1))
model.compile(loss='mse', optimizer='rmsprop')
And this is the error that comes up:
File "/usr/local/lib/python3.4/dist-packages/keras/layers/recurrent.py", line 378, in __init__
super(LSTM, self).__init__(**kwargs)
File "/usr/local/lib/python3.4/dist-packages/keras/layers/recurrent.py", line 97, in __init__
super(Recurrent, self).__init__(**kwargs)
File "/usr/local/lib/python3.4/dist-packages/keras/layers/core.py", line 43, in __init__
self.set_input_shape((None,) + tuple(kwargs['input_shape']))
File "/usr/local/lib/python3.4/dist-packages/keras/layers/core.py", line 138, in set_input_shape
', was provided with input shape ' + str(input_shape))
Exception: Invalid input shape - Layer expects input ndim=3, was provided with input shape (None, 1, 75, 5)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…