我有一个状态 LSTM 定义为顺序模型:
model = Sequential()
model.add(LSTM(..., stateful=True))
...
后来,我将其用作功能模型:
input_1, input_2 = Input(...), Input(...)
output_1 = model(input_1)
output_2 = model(input_2) # Is the state from input_1 preserved?
国家是从input_1
当我们申请时保留model
再次开启input_2
?如果是,如何在调用之间重置模型状态?
下列的关于在 RNN 中使用状态性的注意事项由此link https://keras.io/layers/recurrent/#recurrent and Keras 实现 https://github.com/fchollet/keras/blob/57429d1567b94955ac95afe87792411a420ff0ba/keras/layers/recurrent.py答案是yes if:
- The
batch_size
两个模型中的 是相同的(这很重要,因为 Keras 计算内部状态的方式)。
- 您将首先构建并编译这两个模型,然后使用它们 - 由于某种原因,Keras 正在重置内部状态
build
一层(你可以检查它here https://github.com/fchollet/keras/blob/57429d1567b94955ac95afe87792411a420ff0ba/keras/layers/recurrent.py通过寻找reset_states
方法)。
如果你想重置状态,你可以打电话reset_states
您想要重置状态的每个循环层上的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)