tensorflow data's save and load
阿新 • • 發佈:2018-06-25
int numpy spa pat clas temp 天下 col you
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))
tensorflow data's save and load