码迷,mamicode.com
首页 > 其他好文 > 详细

tensorflow data's save and load

时间:2018-06-25 13:06:30      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:bsp   oba   天下   class   tensor   ssi   nbsp   initial   run   

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

标签:bsp   oba   天下   class   tensor   ssi   nbsp   initial   run   

原文地址:https://www.cnblogs.com/tangpg/p/9223470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!