在TensorFlow里,提供了tf.train.NewCheckpointReader来查看model.ckpt文件中保存的变量信息。
一个简单的例子:
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")
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)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有