TensorFlow加载训练好的模型报错,提示加载路径没有有效的checkpoint文件。
加载模型函数定义如下:
def load_ckpt(ckpt_dir, ckpt_file):
loader = tf.train.Saver()
if ckpt_file is not None:
ckpt = ckpt_dir + '/' + ckpt_file
else:
ckpt = ckpt_dir
loader.restore(self.sess, ckpt)
模型文件如下:
检查代码后发现,上述模型文件在保存时,地址使用了文件名称,此时使用 restore()函数加载模型,直接使用地址将会报错。
使用tf.train.latest_checkpoint()函数可以解决,修改后如下:
loader.restore(self.sess, tf.train.latest_checkpoint(ckpt))
模型成果加载!
(仅用于个人学习过程记录)