gpt4 book ai didi

python - 将有状态 LSTM 称为功能模型?

转载 作者:太空狗 更新时间:2023-10-29 21:56:17 24 4
gpt4 key购买 nike

我有一个定义为顺序模型的有状态 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_2 上再次应用 model 时,来自 input_1 的状态是否保留?如果是,如何在调用之间重置模型状态?

最佳答案

根据此 link 中的在 RNN 中使用有状态性的注意事项Keras implementation如果满足以下条件,则答案是:

  1. 两个模型中的 batch_size 相同(由于 Keras 计算内部状态的方式,这很重要)。
  2. 您将首先构建和编译这两个模型,然后使用它们 - 出于某种原因,Keras 在层的 build 期间重置内部状态(您可以通过查找 来检查 here code>reset_states 方法)。

如果你想重置状态,你可以在你想要重置状态的每个循环层上调用 reset_states 方法。

关于python - 将有状态 LSTM 称为功能模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41759332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com