转载自: https://www.jianshu.com/p/fc11f32800f9
保存checkpoint后,尝试调用保存的模型:
with tf.Session() as sess:
print("Reading checkpoints...")
ckpt = tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
saver.restore(sess, ckpt.model_checkpoint_path)
print('Loading success, global_step is %s' % global_step)
else:
print('No checkpoint file found')
上面是Tensorflow官网给出的模型调用方法,但出现了下面的错误:
ValueError: Variable conv1/weights already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:
原因是在一次测试过程中,测试了多张图片,导致模型的参数需要重复使用,所以需要告诉TF‘允许复用参数’,所以只要在上面的代码加上
tf.get_variable_scope().reuse_variables()
Error就会消失。
with tf.Session() as sess:
tf.get_variable_scope().reuse_variables()
print("Reading checkpoints...")
ckpt = tf.train.get_checkpoint_state(logs_train_dir)
if ckpt and ckpt.model_checkpoint_path:
global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
saver.restore(sess, ckpt.model_checkpoint_path)
print('Loading success, global_step is %s' % global_step)
else:
print('No checkpoint file found')
转载自: https://www.jianshu.com/p/fc11f32800f9