TensorFlow ckpt文件保存方法

http://t.zoukankan.com/tszr-p-10875087.html
zoukankan      html  css  js  c++  java
  
  • 吴裕雄 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,所以这里会报错。

TensorFlow ckpt文件保存方法_第1张图片

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})
Copyright © 2011-2022 走看看
  •   
  • 你可能感兴趣的:(tensorflow,人工智能,python)