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