Variable conv1/weights already exists, disallowed. Did you mean to set reuse=True in VarScope? 解决方法

转载自: 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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值