gpt4 book ai didi

Keras 有状态 LSTM 错误

转载 作者:行者123 更新时间:2023-12-01 07:04:14 25 4
gpt4 key购买 nike

我想在 keras 中创建有状态的 LSTM。我给了它一个这样的命令:

model.add(LSTM(300,input_dim=4,activation='tanh',stateful=True,batch_input_shape=(19,13,4),return_sequences=True))

其中批量大小= 19。但是在运行它会出错
 Exception: In a stateful network, you should only pass inputs with a number of samples that can be divided by the batch size. Found: 8816 samples. Batch size: 32.

我没有在脚本的任何地方指定批处理大小 32,并且 19 可以被 8816 整除

最佳答案

model.fit() 进行批处理(例如,与 model.train_on_batch 相反)。因此它有一个 batch_size参数默认为 32。

将此更改为您的输入批量大小,它应该按预期工作。

例子:

batch_size = 19

model = Sequential()
model.add(LSTM(300,input_dim=4,activation='tanh',stateful=True,batch_input_shape=(19,13,4),return_sequences=True))

model.fit(x, y, batch_size=batch_size)

关于Keras 有状态 LSTM 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39298462/

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