【问题标题】:How to pass a TensorFlow tensor to a TFLearn model如何将 TensorFlow 张量传递给 TFLearn 模型
【发布时间】:2017-08-12 16:00:33
【问题描述】:

我正在 TensorFlow 中开展一个项目,该项目对已经训练好的机器学习模型执行操作。按照教程TFLearn Quickstart,我构建了一个深度神经网络,可以根据Titanic Dataset 预测生存。我想像使用 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 模型上使用张量有什么限制?

【问题讨论】:

    标签: python tensorflow tflearn


    【解决方案1】:

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

    print(model.predict([testTF]))
    

    试试这个:

    print(model.predict(testTF))
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-18
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      相关资源
      最近更新 更多