Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tf.train.get_checkpoint_state always None

Tags:

tensorflow

I am using tf.train.get_checkpoint_state to check whether I have a valid checkpoint file to restore a Tensorflow saved model.

ckpt = tf.train.get_checkpoint_state(os.path.dirname('fi/saves'))
if ckpt and ckpt.model_checkpoint_path:
   saver.restore(sess, ckpt.model_checkpoint_path)  

My issue is that ckpt is always None. Here is the content of my saves directory:

  • internals.pkl
  • stats.json
  • variables.ckpt.data-00000-of-00001
  • variables.ckpt.index

Please note that a call to restore directly works well.

EDIT:

I have tried using the latest_filename argument like this:

tf.train.get_checkpoint_state(os.path.dirname(checkpoint_dir), latest_filename='variables.ckpt.index')  

I am still getting None.

like image 263
ryuzakinho Avatar asked Aug 10 '17 09:08

ryuzakinho


1 Answers

I figured out that tf.train.get_checkpoint_state looks for a checkpoint file.

I did not have this file because I was doing this when saving:

saver.save(sess, variables_file_path, write_meta_graph=False, write_state=False)

Instead of:

saver.save(sess, variables_file_path, write_meta_graph=False, write_state=True)  # write state is true by default.

This now works !

like image 60
ryuzakinho Avatar answered Nov 05 '22 22:11

ryuzakinho