python - RNN 从哪里获取批量大小?

标签 python tensorflow machine-learning neural-network keras

我正在通过以下方式训练 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 中没有使用断点。谢谢

最佳答案

来自Keras documentation

  • 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/

相关文章:

python - 你如何使用 TensorFlow Graphkeys 获取所有权重?

tensorflow - ValueError : Error when checking input: expected dense_1_input to have shape (3, )但得到形状为(2,)的数组

machine-learning - 如何使用计算机视觉来查找图像中的形状?

python - 在相等索引位置有效填充 torch.Tensor

python - 将数组插入sqlite3 python

python - 查询基于索引和数据列的 Pandas 数据框

python - 如何将深度网络分成两个独立的网络?

c++ - 如何使用某种统计方法匹配软聚合特征(眼睛、 Nose 、嘴巴)?

python - pandas DataFrame 将值作为元组进行字典

android - 如何通过 adb(或通过 Python 命令)获取 android 内核版本?