我正在通过以下方式训练 RNN:
def create_rnn_model(stateful,length):
model = Sequential()
model.add(SimpleRNN(20,return_sequences=False,stateful=stateful,batch_input_shape=(1,length,1)))
adam = optimizers.Adam(lr=0.001)
model.add(Dense(1))
model.compile(loss='mean_absolute_error', optimizer=adam, metrics=[root_mean_squared_error])
print(model.summary())
return model
和拟合
model_info = model_rnn_stateful.fit(x=x_train, y=y_train, validation_data=(x_test, y_test), batch_size=1, epochs=10,verbose=1)
并预测
predicted_rnn_stateful = model_rnn_stateful.predict(x_test)
但是当我预测它会抛出错误
ValueError: In a stateful network, you should only pass inputs with a number of samples that can be divided by the batch size. Found: 200 samples. Batch size: 32.
我没有指定 32。我不知道它来自哪里。我的批量大小仅为 1。感谢任何帮助。
编辑 我的脚本/IDE 中没有使用断点。谢谢
最佳答案
- batch_size: Integer or None. Number of samples per gradient update. If unspecified, batch_size will default to 32.
1 可能是batch_size的错误值,因此它采用默认值32。尝试使用2或20作为batch_size
关于python - RNN 从哪里获取批量大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52946030/