tensorflow报错解决方案:ValueError: Variable bidirectional_rnn/fw/lstm_cell/kernel already exists, disallow

ValueError: Variable bidirectional_rnn/fw/lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

  File "XX.py", line 105, in rnn
    outputs, _, _ = tf.contrib.rnn.static_bidirectional_rnn(cell_fw, cell_bw, inputs, dtype=tf.float32)
  File "XX.py", line 57, in __init__
    self.rnn()
  File "XX.py", line 248, in <module>
    model = TextRNN(config)

运行tensorflow程序时,如果出现以上类似的报错,是程序命名空间相同产生错误,对每个函数定义不同的name,即可解决。

cell_fw2 = tf.nn.rnn_cell.LSTMCell(self.config.hidden_dim, name='cell_fw_2')

cell_bw2 = tf.nn.rnn_cell.LSTMCell(self.config.hidden_dim, name='cell_bw_2')


 

猜你喜欢

转载自blog.csdn.net/m511655654/article/details/85125467