小编Fed*_*cia的帖子

如何在Tensorflow中保存估算器供以后使用?

我按照教程"TF图层指南:构建卷积神经网络"(这里是代码:https://github.com/tensorflow/tensorflow/blob/r1.1/tensorflow/examples/tutorials/layers/cnn_mnist .py).

我根据自己的需求调整了教程,即手动检测.

据我所知,本教程创建了估算器(它是一个CNN),然后进行拟合,最后,它评估估计器的性能.现在,我的问题是我想在另一个文件中使用estimator,这将是我的主程序.如何从其他文件访问估算器?每次我想使用它时,我是否必须适合估算器?(我希望不是)

我想知道是否有人可以帮助我了解如何保存估算器以便以后使用它.(据我所知,我不能创建一个saver tf.train.Saver,因为我没有运行会话).

这是我train.py文件中的代码:

def main(unused_argv):

#Load training and eval data (part missing)


# Create the estimator
hand_detector = learn.Estimator(model_fn=cnn_model_fn, model_dir="\cnn_model_fn")

# Set up logging for predictions
# Log the values in the "Softmax" tensor with label "probabilities"
tensors_to_log = {"probabilities": "softmax_tensor"}
logging_hook = tf.train.LoggingTensorHook(
    tensors=tensors_to_log, every_n_iter=50)

# Train the model
hand_detector.fit(
    x=train_data,
    y=train_labels,
    batch_size=100,
    steps=20000,
    monitors=[logging_hook])

# Configure the accuracy metric for evaluation
metrics = {
    "accuracy":
        learn.MetricSpec(
            metric_fn=tf.metrics.accuracy, …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

9
推荐指数
2
解决办法
6868
查看次数

标签 统计

python ×1

tensorflow ×1