Keras Array Input Error

我遇到了以下错误:

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]],   ....   ]

所以您可以尝试使用以下代码重塑它:

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

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注