我想知道如何导出估计器,然后导入它以从 MNIST 教程进行预测,张量流的页面。
谢谢你!
The Estimator
has model_dir
args 将保存模型的位置。所以在预测过程中我们使用Estimator
并致电predict
重新创建图形并加载检查点的方法。
For the MNIST
例如,预测代码为:
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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)