tensorflow1.0 模型的保存与加载

import tensorflow as tf
import numpy as np

# ##Save to file
# W = tf.Variable([[4,5,6],[7,8,9]],dtype=tf.float32,name="weight")
# b = tf.Variable([[2,5,8]],dtype=tf.float32,name="biases")
#
# init = tf.initialize_all_variables()
#
# saver = tf.train.Saver()
#
# with tf.Session() as sess:
#     sess.run(init)
#     save_path = saver.save(sess,"models/model.ckpt")
#     print("save complete")

W = tf.Variable(np.arange(6).reshape((2,3)),dtype=tf.float32,name="weight")
b = tf.Variable(np.arange(3).reshape((1,3)),dtype=tf.float32,name="biases")

saver = tf.train.Saver()

with tf.Session() as sess:
    saver.restore(sess,"models/model.ckpt")
    print(sess.run(W))
    print(sess.run(b))

  

[[4. 5. 6.]
[7. 8. 9.]]
[[2. 5. 8.]]

多思考也是一种努力,做出正确的分析和选择,因为我们的时间和精力都有限,所以把时间花在更有价值的地方。
原文地址:https://www.cnblogs.com/LiuXinyu12378/p/12495407.html