Tensorflow出口估算器进行预测 [英] Tensorflow export estimators for prediction
本文介绍了Tensorflow出口估算器进行预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I wonder how can I export the estimator and then import it for prediction from MNIST tutorial, Tensorflow's page. Thank you!
推荐答案
Estimator
具有model_dir
args,将在其中保存模型.因此,在预测期间,我们使用Estimator
并调用predict
方法,该方法将重新创建图形并加载检查点.
The Estimator
has model_dir
args where the model will be saved. So during prediction we use the Estimator
and call the predict
method which recreates the graph and the checkpoints are loaded.
对于MNIST
示例,预测代码为:
For the MNIST
example, the prediction code would be:
tf.reset_default_graph()
# An input-function to predict the class of new data.
predict_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": eval_data},
num_epochs=1,
shuffle=False)
mnist_classifier = tf.estimator.Estimator(
model_fn=cnn_model_fn, model_dir="/tmp/mnist_convnet_model")
#Prediction call
predictions = mnist_classifier.predict(input_fn=predict_input_fn)
pred_class = np.array([p['classes'] for p in predictions]).squeeze()
print(pred_class)
# Output
# [7 2 1 ... 4 5 6]
这篇关于Tensorflow出口估算器进行预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文