0

我正在训练tensorflow中的模型,并且正在为模型做检查点。我的Checkpoints目录,我有四个文件,即从张量流模型检查点提取权重值

  • checkpoint
  • model.cpkt-0.data-00000-of-00001
  • model.cpkt-0.index
  • model.cpkt-0.meta

现在我想提取我的图表为每一层的权重值, 我怎样才能做到这一点?

我尝试这样做:

import tensorflow as tf 
sess = 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? 

回答

2

您正在恢复一个错误的方式

saver.restore(sess, 'model.cpkt-0') 
# get the graph 
g = tf.get_default_graph() 
w1 = g.get_tensor_by_name('some_variable_name as per your definition in the model')