我在TensorFlow中训练一个模型,并为我的模型设置了检查点。在Checkpoints
目录中,我有四个文件,分别是:
checkpoint
model.cpkt-0.data-00000-of-00001
model.cpkt-0.index
model.cpkt-0.meta
现在我想提取图中每一层的权重值,该如何操作呢?
我尝试了以下方法:
import tensorflow as tfsess = tf.InteractiveSession()saver = tf.train.import_meta_graph('model.cpkt-0.meta')w = saver.restore(sess, 'model.cpkt-0.data-00000-of-00001')
但我遇到了以下错误:
Unable to open table file ./model.cpkt-0.data-00000-of-00001: Data loss: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?
回答:
你恢复的方式不对
saver.restore(sess, 'model.cpkt-0')# 获取图g = tf.get_default_graph()w1 = g.get_tensor_by_name('some_variable_name as per your definition in the model')