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

mlR*_*cks 3 machine-learning 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')
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

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?
Run Code Online (Sandbox Code Playgroud)

Ish*_*nal 5

您的恢复方式有误

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')
Run Code Online (Sandbox Code Playgroud)