Skip to main content
 首页 » 编程设计

python之值错误 : Attempt to have a second RNNCell use the weights of a variable scope that already has weights

2025年02月15日6qlqwjy

我运行了 Tensorflow 1.0 提供的 ptb_word_lm.py,但它显示了这条消息:

ValueError: Attempt to have a second RNNCell use the weights of a variable scope that already has weights: 'Model/RNN/multi_rnn_cell/cell_0/basic_lstm_cell'; and the cell was not constructed as BasicLSTMCell(..., reuse=True). To share the weights of an RNNCell, simply reuse it in your second calculation, or create a new one with the argument reuse=True.

然后我修改代码,将'reuse=True'添加到BasicLSTMCell,但它显示了这条消息:

ValueError: Variable Model/RNN/multi_rnn_cell/cell_0/basic_lstm_cell/weights does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?

我该如何解决这个问题?

请您参考如下方法:

将 reuse = tf.get_variable_scope().reuse 添加到 BasicLSTMCell 对我来说没问题。