【发布时间】:2018-08-24 13:38:35
【问题描述】:
我见过一些人有类似的错误,但似乎没有一个与我有关,而且作为一个对 python 相对较新的人,这有点令人困惑。
我正在使用 Tensorflow + TFLearn 尝试制作一个非常简单的网络,可以根据类型、原产地和年份(不要问)预测鳄梨的价格,但它一直抛出错误:
Cannot feed value of shape (10, 500) for Tensor 'TargetsData/Y:0', which has shape '(?, 1)'
我将 n_class 设置为 500,因为我正在处理一些更高的数字,如果它太低,它会一直抛出错误,但据我了解不是这样,它与“形状”有关",但我真的不知道那是什么意思。
我将粘贴我的完整代码,对不起,如果这是一个不好的问题/一个简单的问题,我只是对这一切很陌生,有点困惑。
data, labels = tflearn.data_utils.load_csv('avocado.csv',
target_column=2,
categorical_labels=True,
n_classes=500,
columns_to_ignore=[0,1,3,4,5,6,7,8,9,10])
for type in data:
if type[0] == "conventional":
type[0] = 1
else:
type[0] = 0
for place in data:
if place[2] == "Albany":
place[2] = 0
elif place[2] == "Atlanta":
place[2] = 1
elif place[2] == "BaltimoreWashington":
place[2] = 2
elif place[2] == "Boise":
place[2] = 3
elif place[2] == "Boston":
place[2] = 4
elif place[2] == "BuffaloRochester":
place[2] = 5
elif place[2] == "California":
place[2] = 6
elif place[2] == "Charlotte":
place[2] = 7
#this goes on for a while, just converting strings to int to work
#with TFLearn
print(data[0])
# define the input layer
# 3 because we have 3 columns in the data set (year, location, and type)
net = tflearn.input_data(shape=[None, 3])
# adding hidden layers
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
# the output layer
net = tflearn.fully_connected(net, 1, activation="softmax")
net = tflearn.regression(net)
# define model
model = tflearn.DNN(net)
# start training
model.fit(data, labels, n_epoch=10, batch_size=10, show_metric=True)
提前感谢您的帮助,如果这是一个愚蠢的问题,再次抱歉。
【问题讨论】:
标签: python tensorflow tflearn