点此进入CSDN

点此添加QQ好友 加载失败时会显示




tensorflow1.0 模型的保存与加载

import tensorflow as tf
import numpy as np

# ##Save to file
# W = tf.Variable([[4,5,6],[7,8,9]],dtype=tf.float32,name="weight")
# b = tf.Variable([[2,5,8]],dtype=tf.float32,name="biases")
#
# init = tf.initialize_all_variables()
#
# saver = tf.train.Saver()
#
# with tf.Session() as sess:
#     sess.run(init)
#     save_path = saver.save(sess,"models/model.ckpt")
#     print("save complete")

W = tf.Variable(np.arange(6).reshape((2,3)),dtype=tf.float32,name="weight")
b = tf.Variable(np.arange(3).reshape((1,3)),dtype=tf.float32,name="biases")

saver = tf.train.Saver()

with tf.Session() as sess:
    saver.restore(sess,"models/model.ckpt")
    print(sess.run(W))
    print(sess.run(b))

  

[[4. 5. 6.]
[7. 8. 9.]]
[[2. 5. 8.]]

posted @ 2020-03-15 00:18  高颜值的殺生丸  阅读(299)  评论(0编辑  收藏  举报

作者信息

昵称:

刘新宇

园龄:4年6个月


粉丝:1209


QQ:522414928