I have an LSTM in Keras that I am training to predict on time series data. I want the network to output predictions on each timestep, as it will receive a new input every 15 seconds. So what I am struggling with is the proper way to train it so that it will output h_0, h_1, ..., h_t, as a constant stream as it receives x_0, x_1, ...., x_t as a stream of inputs. Is there a best practice for doing this?
You can enable statefulness in your LSTM layers by setting stateful=True
. This changes the behavior of the layer to always use the state of the previous invocation of the layer instead of resetting it for each layer.call(x)
.
For example an LSTM layer with 32 units with batch size 1, sequence length 64 and feature length 10:
LSTM(32, stateful=True, batch_input_shape=(1,64,10))
With this successive calls of predict
will use the previous states.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With