如何在 Keras 中重置状态变量?

How to reset state variables in Keras?

我正在构建一个 RNN (LSTM/GRU) 并且我有可变长度的时间序列。每个时间序列完成后如何重置状态变量?我想在 Keras 中执行此操作,但如果我必须在 Theano(我的后端)中构建 RNN,那也很好。

它不在 Keras 的文档中,但循环层有一个 .reset_state() 函数。您可以在 github 上找到它,您可以重置一层或整个模型的状态。

在 Keras 文档中,Chapter on Recurrent Layers

To reset the states of your model, call .reset_states() on either a specific layer, or on your entire model.

例如:

model.predict()

model.reset_states()