What should be Output shape of keras model layers
Since you set the parameter return_sequences
to True
in the LSTM
layer, you are getting a sequence with the same number of time steps as your input and an output space of 1 for each timestep, hence the shape (None, 129, 1)
. Afterwards, you apply a Dense
layer to this tensor, but this layer is always applied to the last dimension of a tensor, which in your case is 1 and not 129. Therefore you get the output (None, 129, 64)
. Then, you use a final output layer, which is also applied to the last dimension of your tensor resulting in output with the shape (None, 129, 1)
. The Tensorflow docs also explain this behavior:
If the input to the layer has a rank greater than 2, then Dense computes the dot product between the inputs and the kernel along the last axis of the inputs and axis 0 of the kernel (using tf.tensordot).
You can set return_sequences
to False
if you want to work with a 2D output (batch_size, features)
instead of 3D (batch_size, time_steps, features)
, or you can use the Flatten
layer.