gpt4 book ai didi

python-3.x - tflearn DNN 模型给出 TargetsData/Y :0 error

转载 作者:行者123 更新时间:2023-11-30 09:49:50 26 4
gpt4 key购买 nike

我收到以下错误...

ValueError: Cannot feed value of shape (16,) for Tensor 'TargetsData/Y:0', which has shape '(?, 16)'

我知道这与我的 Y 变量的形状有关,在本例中是变量 labels,但我不确定如何更改形状以使我的模型发挥作用。

基本上,我有一个 CSV 文件,我使用 pandas 将其保存到变量中...

data = pd.read_csv('Speed Dating Data.csv')

经过一些预处理后,我决定像这样提取我的目标类......

# Target label used for training
labels = np.array(data["age"], dtype=np.float32)

接下来,我从我的 data 变量中删除了此列...

# Data for training minus the target label.
data = np.array(data.drop("age", axis=1), dtype=np.float32)

然后我决定建立我的模型......

net = tflearn.input_data(shape=[None, 32])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 16, activation='softmax')
net = tflearn.regression(net)

# Define model.
model = tflearn.DNN(net)

model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)

如果我运行这个,我会收到上面的错误。由于我的 labels 似乎是 (16,) 但我需要它是 (?, 16),我尝试了以下代码。 .

labels = labels[np.newaxis, :]

但这又产生了另一个错误。我想我不确定我的目标类 labels 应该是什么形式。我该如何解决这个问题?

最佳答案

根据以下内容 reshape 您的标签

label= np.reshape(label,(-1,16)) # since you have 16 classes

标签 reshape 为 (?,16)。

希望这有帮助。

根据您的要求进行更新。并添加了对更改的评论。

labels = np.array(data["age"], dtype=np.float32)
label= np.reshape(label,(-1,1)) #reshape to [6605,1]

data = np.array(data.drop("age", axis=1), dtype=np.float32)

net = tflearn.input_data(shape=[None, 32])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 1, activation='softmax') #Since this is a regression problem only one output
net = tflearn.regression(net)

# Define model.
model = tflearn.DNN(net)

model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)

关于python-3.x - tflearn DNN 模型给出 TargetsData/Y :0 error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47148666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com