LouisScorpio / datamining

learn in datamining
522 stars 848 forks source link

运行train_lstm()时报错 #9

Open zhouhaopku opened 7 years ago

zhouhaopku commented 7 years ago

Attempt to have a second RNNCell use the weights of a variable scope that already has weights: 'rnn/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. 我查了stackoverflow,按照上面问题将rnn.BasicLSTMCell(rnn_unit)修改成cell=rnn.BasicLSTMCell(rnn_unit, reuse=True)或者rnn.BasicLSTMCell(rnn_unit,reuse = tf.get_variable_scope().reuse)还是报错: ValueError: Variable rnn/basic_lstm_cell/weights already exists, disallowed. Did you mean to set reuse=True in VarScope? 请问是怎么运行该代码啊?

std-in commented 6 years ago
with tf.variable_scope('cell_def', reuse=tf.AUTO_REUSE):
    cell = tf.nn.rnn_cell.BasicLSTMCell(rnn_unit)
with tf.variable_scope('rnn_def', reuse=tf.AUTO_REUSE):
    output_rnn, final_states = tf.nn.dynamic_rnn(cell, input_rnn,
                                             initial_state=init_state,
                                             dtype=tf.float32)
RalphWithoutMissFun commented 6 years ago

thanks