解决Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?

ValueError: Variable seq2seq/decoder/attention_v already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?

这个错误是在测试的时候遇到的,训练没有问题,开始还以为是重复定义相同的变量名,

后来才明白,之前运行的模型加载到内存中没有清空就开始第二次运行,会导致tensorflow检查到两次变量名相同。

解决方法,在第二次构建计算图的时候清空之前的计算图,如下G为定义的模型类,G.placeholder构建占位符,G.build_graph构建计算图

tf.reset_default_graph()
G.build_placeholder()
G.build_graph()

猜你喜欢

转载自blog.csdn.net/firesolider/article/details/113138743