numpy - Keras 数组输入错误

标签 numpy machine-learning tensorflow deep-learning keras

我收到以下错误:

ValueError: 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 6 arrays but instead got the following list of 3 arrays: [array([[ 0,  0,  0, ..., 18, 12,  1],
       [ 0,  0,  0, ..., 18, 11,  1],
       [ 0,  0,  0, ..., 18,  9,  1],
       ...,
       [ 0,  0,  0, ..., 18, 15,  1],
       [ 0,  0,  0, ..., 18,  9,  ...

在我的 keras 模型中。

我认为模型弄错了什么?

当我向模型提供输入时会发生这种情况。相同的输入在另一个程序中运行得非常好。

最佳答案

如果没有更多信息,就不可能诊断出您的确切问题。

我通常根据我的训练数据X指定第一层的input_shape参数。

例如

model = Sequential()
model.add(Dense(32, input_shape=X.shape[0]))

我认为您会希望 X 看起来像这样:

   [
    [[ 0,  0,  0, ..., 18, 11,  1]],
    [[ 0,  0,  0, ..., 18,  9,  1]],
   ....
   ]

所以你可以尝试使用以下行 reshape 它:

X = np.array([[sample] for sample in X])

关于numpy - Keras 数组输入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41248677/

相关文章:

python - Python中笛卡尔坐标中四个点的二面角/扭转角

machine-learning - 将特征误差纳入随机森林算法

matlab - Netlab的函数mlperr计算均方误差吗?

python - 有没有办法下载 PoseNet 的卡住图(.pb 文件)?

python - 为什么我的 LSTM 在 tensorflow 中学习得这么慢而且很糟糕?

python - 在另一个包含多个二维数组的数组中查找二维数组的最快方法

Python、Numpy 堆栈溢出

python - numpy memmap内存使用-想要迭代一次

machine-learning - 具有定制损失函数的随机森林

python - LSTM 模型在第一个 epoch 后的 val_acc 为 1.0?