Skip to content Skip to sidebar Skip to footer

Typeerror When Trying To Create A Blstm Network In Keras

I'm a bit new to Keras and deep learning. I'm currently trying to replicate this paper but when I'm compiling the second model (with the LSTMs) I get the following error: 'TypeErro

Solution 1:

Your problem lies in these three lines:

BLSTM1 = layers.Bidirectional(layers.LSTM(128, input_shape=(8,40,96)))(merge_layer)
print(BLSTM1.shape)
BLSTM2 = layers.Bidirectional(layers.LSTM(128))(BLSTM1)

As a default, LSTM is returning only the last element of computations - so your data is losing its sequential nature. That's why the proceeding layer raises an error. Change this line to:

BLSTM1 = layers.Bidirectional(layers.LSTM(128, return_sequences=True))(merge_layer)
print(BLSTM1.shape)
BLSTM2 = layers.Bidirectional(layers.LSTM(128))(BLSTM1)

In order to make the input to the second LSTM to have sequential nature also.

Aside of this - I'd rather not use input_shape in middle model layer as it's automatically inferred.

Post a Comment for "Typeerror When Trying To Create A Blstm Network In Keras"