TFLearn 无法正确加载训练数据的形状

我正在尝试使用 TensorFlow 和 TFLearn 创建一个 AI 来预测 FRC 比赛的比赛结果。

以下是相关代码:

x = np.load("FRCPrediction/matchData.npz")["x"]y = np.load("FRCPrediction/matchData.npz")["y"]def buildModel():    net = tflearn.input_data([10, 0])    net = tflearn.fully_connected(net, 64)    net = tflearn.dropout(net, 0.5)    net = tflearn.fully_connected(net, 10, activation='softmax')    net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy')    model = tflearn.DNN(net)    return modelmodel = buildModel()BATCHSIZE = 128model.fit(x, y, batch_size = BATCHSIZE)

它出现了以下错误:

Training samples: 36024Validation samples: 0-----------------------------------------------------------------------------ValueError                                Traceback (most recent call last)<ipython-input-12-ce7cbb8e618a> in <module>()----> 1 model.fit(x, y, batch_size = BATCHSIZE)4 frames/usr/local/lib/python3.6/dist-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)   1126                              'which has shape %r' %   1127                              (np_val.shape, subfeed_t.name,-> 1128                               str(subfeed_t.get_shape())))   1129           if not self.graph.is_feedable(subfeed_t):   1130             raise ValueError('Tensor %s may not be fed.' % subfeed_t)ValueError: Cannot feed value of shape (128, 36) for Tensor 'InputData/X:0', which has shape '(?, 10, 0)

任何帮助都将不胜感激。谢谢。


回答:

这个错误意味着您的 X 维度是 (some_length, 36),无法适应输入层的维度 (10, 0)。我怀疑您第二个维度为 0 的设置,至少应该为 1。要解决这个问题,您应该这样做:

net = tflearn.input_data(shape=[None, 36])

None 用于动态维度,这将与所有 BATCHSIZE 匹配,无论是 128、1000 还是 2000

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中创建了一个多类分类项目。该项目可以对…

发表回复

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