Search code examples
kerasdeep-learningstatelstmsummary

How to display all LSTM states in Keras summary?


When using the keras feature model.summary() it shows me the tensor shapes of my model which is very nice! Unfortunately, when using a encoder LSTM, called with the keras.layers.LSTM constructor with the property return_states=True, the summary is not displayed in its full form. It looks something like this:

Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input (InputLayer)              (None, 34, 30)       0                                            
__________________________________________________________________________________________________
encoder (LSTM)                  [(None, 34, 30), (No 7320        input[0][0]                      
__________________________________________________________________________________________________
lambda_8 (Lambda)               (None, 34, 15)       0           encoder[0][0]                    
__________________________________________________________________________________________________
decoder (LSTM)                  (None, 34, 30)       5520        lambda_8[0][0]                   
                                                                 encoder[0][1]                    
                                                                 encoder[0][2]                    
==================================================================================================
Total params: 12,840
Trainable params: 12,840
Non-trainable params: 0
__________________________________________________________________________________________________

As you can see the output shape of the encoder is cut off and only the first of the three shapes is visible. Is there a way to display it, maybe a fix or even a workaround? :)


Solution

  • Found a workaround:

    print(encoder.output_shape)
    >> [(None, 34, 30), (None, 30), (None, 30)]