Tensorflow服务训练好的模型与saved_model保存在一起

时间:2019-02-04 22:04:23

标签: tensorflow

我发现tf.saved_model文档不清楚,是否有任何有价值的资源来在其他会话中读取经过训练的模型?

1 个答案:

答案 0 :(得分:0)

这很容易:

# Clear the default graph if any
tf.reset_default_graph()
# Create a saver/loader object
loader = tf.train.Saver()
# Build the same graph architecture (Easiest to do with a class)
model = YourModel()
# Create a session
with tf.Session() as sess:
    # Initialize the variables in the graph
    sess.run(tf.global_variables_initializer())
    # Restore the learned weights from a saved checkpoint
    loader.restore(sess, path_to_checkpoint_dir)