简体   繁体   English

如何将TensorFlow张量传递给TFLearn模型

[英]How to pass a TensorFlow tensor to a TFLearn model

I am working on a project in TensorFlow that performs operations on already-trained machine learning models. 我正在TensorFlow中的一个项目上执行,该项目对已经训练过的机器学习模型进行操作。 Following the tutorial TFLearn Quickstart , I built a deep neural network that predicts survival from the Titanic Dataset . 遵循TFLearn Quickstart教程,我构建了一个深度神经网络,该网络可以从Titanic数据 集中预测生存情况。 I would like to use the TFLearn model in the same way that I would use a TensorFlow model. 我想以与使用TensorFlow模型相同的方式来使用TFLearn模型。

The TFLearn docs homepage says TFLearn文档首页说

Full transparency over Tensorflow. Tensorflow完全透明。 All functions are built over tensors and can be used independently of TFLearn 所有功能都基于张量构建,可以独立于TFLearn使用

This makes me think that I would be able to pass tensors as inputs, etc. to the the TFLearn model. 这使我认为我可以将张量作为输入等传递给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]))

At present, when I pass a tensor into the model I am greeted with ValueError: setting an array element with a sequence. 目前,当我将张量传递到模型中时,会遇到ValueError:用序列设置数组元素。

Specifically, how can you pass tensors into a TFLearn model? 具体来说,如何将张量传递到TFLearn模型中? Generally, what limits are placed on how I can use tensors on a TFLearn model? 通常,在TFLearn模型上如何使用张量受到什么限制?

I don't know if you're still looking for an answer to your problem, but I think the issue is on your very last line: 我不知道您是否还在寻找问题的答案,但我认为问题出在您的最后一行:

print(model.predict([testTF]))

Try this instead: 尝试以下方法:

print(model.predict(testTF))

I think that you nested a list inside another list. 我认为您在另一个列表中嵌套了一个列表。 This isn't a TFlearn issue per se . 这不是一个问题TFlearn 本身 Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在TensorFlow中的模型中将标量张量转换为标量? - How to convert a scalar tensor to scalar in a model in TensorFlow? 如何使用 tflearn model 将我的 tensorflow 2 转换为 graph.pb 文件 - how Convert my tensorflow 2 using tflearn model to graph.pb file 如何使用Tensorflow tflearn进行单词分类 - How to do word classification with Tensorflow tflearn 如何将自动编码器分为编码器和解码器(TensorFlow + TFLearn) - How to separate autoencoder into encoder and decoder (TensorFlow + TFLearn) 如何将 model 的输入张量传递给损失 function? - How to pass the input tensor of a model to a loss function? tflearn /张量流| 多流/多尺度/集合模型定义 - tflearn / tensorflow | Multi-stream/Multiscale/Ensemble model definition 如何在 tensorflow 中将扁平的暗淡张量传递给 Conv2D? - How to pass flatten dim tensor to Conv2D in tensorflow? 如何保存/恢复tensorflow的tensor_forest模型? - how to save/restore tensor_forest model of tensorflow? 如何在未定义变量的情况下保存张量流模型(省略标签张量) - How to save a tensorflow model (omitting the labels tensor) with no variables defined 运行张量流模型时如何检查每个张量的尺寸? - how to check the dimension of each tensor when running a tensorflow model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM