前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tf34:从ckpt中读取权重值

tf34:从ckpt中读取权重值

作者头像
MachineLP
发布2022-05-09 14:58:11
1.1K0
发布2022-05-09 14:58:11
举报
文章被收录于专栏:小鹏的专栏小鹏的专栏

在TensorFlow里,提供了tf.train.NewCheckpointReader来查看model.ckpt文件中保存的变量信息。

一个简单的例子:

代码语言:javascript
复制
import tensorflow as tf
  
w = tf.Variable(2, dtype=tf.float32, name='w')  
b = tf.Variable(1, dtype=tf.float32, name='b')  

x = tf.placeholder(tf.float32, shape=[1], name='x')  
  
logit = w * x + b
  
init = tf.initialize_all_variables()  
  
saver = tf.train.Saver()  
  
with tf.Session() as sess:  
    sess.run(init)  
    saver.save(sess, "./model.ckpt") 
代码语言:javascript
复制
import tensorflow as tf
  
reader = tf.train.NewCheckpointReader("./model.ckpt")  
  
variables = reader.get_variable_to_shape_map()  
  
for v in variables: 
    w = reader.get_tensor(v)  
    print(type(w))  
    # print(w.shape) 
    # print (w[0]) 
    print(w)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-02-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档