从张量流模型检查点提取权重值

时间:2017-08-08 08:08:50

标签: machine-learning tensorflow neural-network deep-learning conv-neural-network

我在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?

1 个答案:

答案 0 :(得分:4)

你正在以错误的方式恢复

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')