【发布时间】:2016-09-19 05:47:46
【问题描述】:
我正在尝试使用 keras train_on_batch 函数训练 nn。我有 39 个功能,并且希望一批包含 32 个样本。因此,每次训练迭代我都有一个包含 32 个 numpy 数组的列表。
这是我的代码(这里每个 batch_x 是一个包含 32 个 numpy 数组的列表,每个数组包含 39 个特征):
input_shape = (39,)
model = Sequential()
model.add(Dense(39, input_shape=input_shape)) # show you is only first layer
...
for batch_x, batch_y in train_gen:
model.train_on_batch(batch_x, batch_y)
但是我突然报错了:
Exception: Error when checking model input: the list of Numpy arrays
that you are passing to your model is not the size the model expected.
Expected to see 1 arrays but instead got the following list of 32 arrays:
我不太确定出了什么问题。
附:我还尝试了不同的input_shape,例如 (32, 39)、(39, 32) 等。
【问题讨论】:
标签: python python-2.7 machine-learning keras training-data