0

我正在 TensorFlow 中开展一个项目,该项目对已经训练好的机器学习模型执行操作。按照教程TFLearn 快速入门,我构建了一个深度神经网络,可以根据泰坦尼克号数据集预测生存。我想以与使用 TensorFlow 模型相同的方式使用 TFLearn 模型。

TFLearn 文档主页说

完全透明的 TensorFlow。所有函数都建立在张量之上,可以独立于 TFLearn 使用

这让我觉得我可以将张量作为输入等传递给 TFLearn 模型。

# Build neural network
net = tflearn.input_data(shape=[None, 6])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net)

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

test = preprocess([[3, 'Jack Dawson', 'male', 19, 0, 0, 'N/A', 5.0000]], to_ignore)
# Make into a tensor
testTF = [tf.constant(i) for i in test]
# Pass the tensor into the predictor
print(model.predict([testTF]))

目前,当我将张量传递给模型时,我会遇到ValueError: setting an array element with a sequence。

具体来说,如何将张量传递给 TFLearn 模型?一般来说,我如何在 TFLearn 模型上使用张量有什么限制?

4

1 回答 1

0

我不知道您是否仍在寻找问题的答案,但我认为问题出在您的最后一行:

print(model.predict([testTF]))

试试这个:

print(model.predict(testTF))

我认为您将一个列表嵌套在另一个列表中。这本身不是 TFlearn 问题。希望有帮助。

于 2017-08-12T08:00:33.910 回答