Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting weights values from a tensorflow model checkpoint

I am training a model in tensorflow and I am doing checkpoints for my model. I the Checkpoints directory, I have four files namely,

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

Now I want to extract the weights values for each layer in my graph, how can I do that?

I tried this:

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

But I am getting the following error:

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?
like image 322
enterML Avatar asked Feb 05 '26 12:02

enterML


1 Answers

You are restoring in a wrong way

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')
like image 115
Ishant Mrinal Avatar answered Feb 09 '26 01:02

Ishant Mrinal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!