Keras in R, LSTM with flexible inputlength

Viewed 321

I'm using Keras with tensorflow backend in R. I want to create a model that can handle an arbitrary input sequence length. When I try to define the following model:

model <- keras_model_sequential() 
layer_lstm(model, 128, input_shape = c(NULL, 5))

I get the following error:

ValueError: Input 0 is incompatible with layer lstm_3: expected ndim=3, found ndim=2

I guess that it runs into difficulties since the batchsize is already variable. So I could do the following:

model <- keras_model_sequential()
layer_lstm(model, 128, input_shape = c(20, NULL, 5))

This runs without any error. Does this indeed signify a fixed batchsize of 20 a variable sequence length and an input lenght of 5? Or is this just wishfull thinking?

0 Answers
Related