愿天堂没有Tensorflow! 阿门。
ValueError: Variable conv1/weights already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:
将一个模型训练好,并且保存了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')