gaussic / text-classification-cnn-rnn

CNN-RNN中文文本分类,基于TensorFlow
MIT License
4.16k stars 1.47k forks source link

执行完train,执行test时报错Variable embedding already exists, disallowed. #88

Closed jiyongjie1234 closed 6 years ago

jiyongjie1234 commented 6 years ago

您好,我用的tf1.10的版本,执行train没有问题,但执行test时,报错Variable embedding already exists, disallowed.Did you mean to set reuse=tf.AUTO_REUSE in VarScope? 这个查了下说是Variable embedding名称重复的问题。应该如何处理呢?

gaussic commented 6 years ago

是否有修改过代码

jiyongjie1234 commented 6 years ago

完全没有改过,直接用您的代码执行,在anconda的spyder中执行train没问题,执行test 报如上错误。应该是embedding = tf.get_variable('embedding', [self.config.vocab_size, self.config.embedding_dim]) 这里embedding的名字重复了,我也不太理解。

gaussic commented 6 years ago

在什么环境下运行,notebook还是spyder

jiyongjie1234 commented 6 years ago

在spyder下运行报错,直接在cmd中执行python run_cnn test 就没问题了,很奇怪

gaussic commented 6 years ago

embedding层只能实例化一次,在spyder里面会保留运行后的实例,所以运行完train再运行test时就会报上面的问题,如果要在spyder中运行,需要修改代码结构。

jiyongjie1234 commented 6 years ago

好的,了解了,感谢