Stream Output of Predictions in Keras

北城余情 提交于 2019-12-13 11:37:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38081263/stream-output-of-predictions-in-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!