Keras中预测的流输出 [英] Stream Output of Predictions in Keras
问题描述
我在Keras中有一个LSTM,正在接受培训以预测时间序列数据.我希望网络在每个时间步上输出预测,因为它将每15秒接收一次新输入.因此,我正在苦苦挣扎的是正确的训练方法,以便它在接收到x_0,x_1,...,x_t作为输入流的同时,将h_0,h_1,...,h_t作为恒定流输出. .有这样做的最佳实践吗?
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?
推荐答案
您可以通过设置 stateful=True
.这会将层的行为更改为始终使用该层的上一次调用状态,而不是为每个layer.call(x)
重置该状态.
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)
.
例如具有32个单位的LSTM层,批处理大小为1,序列长度为64,特征长度为10:
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))
此后predict
的连续调用将使用以前的状态.
With this successive calls of predict
will use the previous states.
这篇关于Keras中预测的流输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!