Python Tflearn - ValueError: Cannot feed value of shape (16, 1) for Tensor u'InputData/X:0', which has shape '(?, 2)'

Python Tflearn - ValueError: Cannot feed value of shape (16, 1) for Tensor u'InputData/X:0', which has shape '(?, 2)'

作为机器学习的新手,tflearn/tensorflow 我正在尝试学习 tflearn(泰坦尼克号)的快速入门教程。

修改它以满足我的需要我得到了这个代码:

from __future__ import print_function

import numpy as np
import tflearn

# Load CSV file, indicate that the first column represents labels
from tflearn.data_utils import load_csv
data, labels = load_csv('nowcastScaled.csv', target_column=1, n_classes=2)

# Preprocessing function
def preprocess(data):
    return np.array(data, dtype=np.float32)

# Preprocess data
data = preprocess(data)

# Build neural network
net = tflearn.input_data(shape=[None, 2])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.001,
                         loss='categorical_crossentropy')

# Define model
model = tflearn.DNN(net)
# Start training (apply gradient descent algorithm)
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)

但是我得到了这个错误:

ValueError: Cannot feed value of shape (16, 1) for Tensor u'InputData/X:0', which has shape '(?, 2)'

我的 csv 文件由 2 列组成,一列是索引(条目编号,因为这只是一个测试,我将自己限制为 100 个条目),另一列是拥塞分数(我正在尝试的) predict, between 0 and 200), 均为数值

我有点明白我试图给它一个错误的值(或者至少是他不在等待的东西)但我不知道如何纠正它。

添加

data = np.reshape(data, (-1, 2))

纠正了我的问题,但给了我同样的错误,但这次是 Y,所以我做了:

labels = np.reshape(labels, (-1, 2))

在回归之前,它似乎已经成功了。我不知道这是否是最好的甚至是好的方法,但现在我设法解决了这个错误。