import tensorflowas tf
保存
v1 = tf.Variable(tf.constant(1.0,shape=[1]),name="v1")
v2 = tf.Variable(tf.constant(2.0,shape=[1]),name="v2")
result = v1 + v2
saver = tf.train.Saver()
with tf.Session()as sess:
sess.run(tf.global_variables_initializer())
savr_path = saver.save(sess,"./model/model.ckpt")
print(savr_path)
读取
import tensorflowas tf
v1 = tf.Variable(tf.constant(1.0,shape=[1]),name="v1")
v2 = tf.Variable(tf.constant(2.0,shape=[1]),name="v2")
result = v1 + v2
saver = tf.train.Saver()
with tf.Session()as sess:
saver.restore(sess,"./model/model.ckpt")# 注意此处路径前添加"./"
print(sess.run(result))# [ 3.]
网友评论