繁体   English   中英

TFLearn无法正确输入Y值

[英]TFLearn cannot feed Y value properly

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

以下是相关代码:

x = np.load("FRCPrediction/matchData.npz")["x"]
y = np.load("FRCPrediction/matchData.npz")["y"]

def buildModel():
    net = tflearn.input_data(shape = [None, 36])
    net = tflearn.fully_connected(net, 64)
    net = tflearn.dropout(net, 0.5)
    net = tflearn.fully_connected(net, 128, activation = "linear")
    net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy')
    net = tflearn.fully_connected(net, 1, activation = "linear")
    model = tflearn.DNN(net)
    return model

model = buildModel()

BATCHSIZE = 128

model.fit(x, y, batch_size = BATCHSIZE)

它因错误而失败:

---------------------------------
Run id: 67BLHP
Log directory: /tmp/tflearn_logs/
---------------------------------
Training samples: 36024
Validation samples: 0
--
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-1b097e6d2ec5> in <module>()
      1 for i in range(EPOCHS):
----> 2     history = model.fit(x, y, batch_size = BATCHSIZE)
      3     print(history)

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,) for Tensor 'TargetsData/Y:0', which has shape '(?, 128)'

任何帮助深表感谢。

为了计算所有变量的梯度,优化器应该在所有层之后使用高级TFlearn API,这是Tensorflow的编码风格所固有的(对于低级tf,我们这样做)。 文档很好地说明了它的工作方式,也许您应该看看或搜索有关此API的其他教程。 要回答您的问题,请尝试:

import tflearn
import numpy as np

x = np.ones((1000, 36))
y = np.zeros((1000, 1))

def buildModel():
    net = tflearn.input_data(shape=[None, 36])
    net = tflearn.fully_connected(net, 64)
    net = tflearn.dropout(net, 0.5)
    net = tflearn.fully_connected(net, 128, activation="linear")
    net = tflearn.fully_connected(net, 1, activation="linear")
    net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy')
    model = tflearn.DNN(net)
    return model

model = buildModel()

BATCHSIZE = 128

model.fit(x, y, batch_size=BATCHSIZE)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM