4

基于此 github 链接https://github.com/brightmart/text_classification/tree/master/a03_TextRNN当我使用 google_news_wor22vec.bin 和带有我的文档 + 标签的文本文件运行a03_TextRNN 时遇到这些错误:

我该如何解决这个问题?

错误图像

    Traceback (most recent call last):
  File "p8_TextRNN_train.py", line 184, in <module>
    tf.app.run()
  File "/home/eslami/anaconda3/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "p8_TextRNN_train.py", line 68, in main
    vocab_size, FLAGS.embed_size, FLAGS.is_training)
  File "/home/eslami/Downloads/all-kind-text_classification-master/a03_TextRNN/p8_TextRNN_model.py", line 33, in init
    self.instantiate_weights()
  File "/home/eslami/Downloads/all-kind-text_classification-master/a03_TextRNN/p8_TextRNN_model.py", line 45, in instantiate_weights
    self.Embedding = tf.get_variable("Embedding",shape=[self.vocab_size, self.embed_size],initializer=self.initializer) #[vocab_size,embed_size] tf.random_uniform([self.vocab_size, self.embed_size],-1.0,1.0)
  File "/home/eslami/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/variable_scope.py", line 1065, in get_variable
    use_resource=use_resource, custom_getter=custom_getter)
  File "/home/eslami/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/variable_scope.py", line 962, in get_variable
    use_resource=use_resource, custom_getter=custom_getter)
  File "/home/eslami/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/variable_scope.py", line 367, in get_variable
    validate_shape=validate_shape, use_resource=use_resource)
  File "/home/eslami/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/variable_scope.py", line 352, in _true_getter
    use_resource=use_resource)
      File "/home/eslami/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/variable_scope.py", line 664, in _get_single_variable
        name, "".join(traceback.format_list(tb))))

    ValueError: Variable Embedding already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:
File "/home/eslami/Downloads/all-kind-text_classification-master/a03_TextRNN/p8_TextRNN_model.py", line 45, in instantiate_weights
    self.Embedding = tf.get_variable("Embedding",shape=[self.vocab_size, self.embed_size],initializer=self.initializer) #[vocab_size,embed_size] tf.random_uniform([self.vocab_size, self.embed_size],-1.0,1.0)
  File "/home/eslami/Downloads/all-kind-text_classification-master/a03_TextRNN/p8_TextRNN_model.py", line 33, in init
    self.instantiate_weights()
  File "/home/eslami/Downloads/all-kind-text_classification-master/a03_TextRNN/p8_TextRNN_model.py", line 123, in test
    textRNN=TextRNN(num_classes, learning_rate, batch_size, decay_steps, decay_rate,sequence_length,vocab_size,embed_size,is_training)
4

1 回答 1

2

这已经很晚了,但是我在寻找解决类似问题时找到了您的帖子。万一其他人在这里找到了方法,请在模型的开头添加此代码将解决问题:

tf.reset_default_graph()

于 2020-01-21T19:52:20.853 回答