.Tang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

note:

if you'll load data,the data shape should be similar with saved data's shape.    -- 中式英语,天下无敌

 

import tensorflow as tf
import numpy as np

# save variable data
W = tf.Variable([[2, 3], [3, 4]], dtype=tf.float32)
b = tf.Variable([[3, 4]], dtype=tf.float32)

init = tf.global_variables_initializer()
saver = tf.train.Saver()
with tf.Session() as sess:
    sess.run(init)
    saver_path = saver.save(sess, 'templates/save_net.ckpt')
    print("save path in --", saver_path)


# load saved Variable's data
W = tf.Variable(np.arange(2).reshape((1, 2)), dtype=tf.float32)  # 2, 2)  二行两列
b = tf.Variable(np.arange(2).reshape((2, 2)), dtype=tf.float32)  # (1, 2)  一行两列

saver = tf.train.Saver()

with tf.Session() as sess:
    saver.restore(sess, 'templates/save_net.ckpt')
    print("W: ", sess.run(W))
    print("b: ", sess.run(b))

 

posted on 2018-06-25 11:13  .Tang  阅读(275)  评论(0编辑  收藏  举报