编程语言
首页 > 编程语言> > 吴裕雄 python 神经网络——TensorFlow ckpt文件保存方法

吴裕雄 python 神经网络——TensorFlow ckpt文件保存方法

作者:互联网

import tensorflow as tf

v1 = tf.Variable(tf.random_normal([1], stddev=1, seed=1))
v2 = tf.Variable(tf.random_normal([1], stddev=1, seed=1))
result = v1 + v2

init_op = tf.global_variables_initializer()
saver = tf.train.Saver()

with tf.Session() as sess:
    sess.run(init_op)
    saver.save(sess, "E:\\Saved_model\\model.ckpt")

with tf.Session() as sess:
    saver.restore(sess, "E:\\Saved_model\\model.ckpt")
    print(sess.run(result))

saver = tf.train.import_meta_graph("E\\Saved_model\\model.ckpt.meta")
v3 = tf.Variable(tf.random_normal([1], stddev=1, seed=1))

with tf.Session() as sess:
    saver.restore(sess, "Saved_model/model.ckpt")
    print sess.run(v1) 
    print sess.run(v2) 
    print sess.run(v3)#直接加载持久化的图。因为之前没有导出v3,所以这里会报错。

v1 = tf.Variable(tf.constant(1.0, shape=[1]), name = "other-v1")
v2 = tf.Variable(tf.constant(2.0, shape=[1]), name = "other-v2")
saver = tf.train.Saver({"v1": v1, "v2": v2})

 

标签:sess,python,saver,v2,v1,ckpt,tf,TensorFlow,model
来源: https://www.cnblogs.com/tszr/p/10875087.html