Tensorflow Error笔记1

愿天堂没有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')
**Error消失**
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容