gpt4 book ai didi

python - 用于预测的 Tensorflow 导出估计器

转载 作者:行者123 更新时间:2023-12-01 01:52:07 25 4
gpt4 key购买 nike

我想知道如何导出估计器,然后从 MNIST 教程 Tensorflow's page 导入它进行预测。谢谢!

最佳答案

Estimator 具有用于保存模型的 model_dir 参数。因此,在预测期间,我们使用 Estimator 并调用 predict 方法来重新创建图形并加载检查点。

对于 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]

关于python - 用于预测的 Tensorflow 导出估计器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50612923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com