Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream Output of Predictions in Keras

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?

enter image description here

like image 620
Rob Avatar asked Jun 28 '16 16:06

Rob


1 Answers

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.

like image 51
nemo Avatar answered Oct 21 '22 19:10

nemo