tf.train.get_checkpoint_state()
先看下官方文档对于接口的定义了解函数的使用
一 定义
Args:
- checkpoint_dir:chechpoint文件的路径
- latest_filename:指定chechpoint的名字,默认是'checkpoint'
Returns:
- 如果路径有效则返回一个CheckpointState proto对象(该对象有两个可用的属性值),否则返回None
Rasies:
- ValueError:如果checkpoint 读取器没有读取路径会跑出ValueError
二 CheckpointState proto对象
CheckpointState proto对象有两个可用属性。
- model_checkpoint_path:最新的chechpoint路径
- all_model_checkpoint_paths:文件中所有的checkpoints路径列表
三栗子
给出cifar10中是使用实例
ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
if ckpt and ckpt.model_checkpoint_path:
# Restores from checkpoint
saver.restore(sess, ckpt.model_checkpoint_path)
global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
else:
print('No checkpoint file found')