Tensorflow ValueError: Attempt to reuse RNNCell with a different variable scope than its first

来源:互联网 发布:篮球突破技巧 知乎 编辑:程序博客网 时间:2024/06/08 19:43

Reference:
https://stackoverflow.com/questions/42669578/tensorflow-1-0-valueerror-attempt-to-reuse-rnncell-with-a-different-variable-s

原本代码:

cell = tf.contrib.rnn.LSTMCell(state_size, state_is_tuple=True)rnn_cells = tf.contrib.rnn.MultiRNNCell([cell for _ in range(num_layers)], state_is_tuple = True)outputs, current_state = tf.nn.dynamic_rnn(rnn_cells, x, initial_state=rnn_tuple_state, scope = "layer")

修改后:

def lstm_cell():    return tf.contrib.rnn.LSTMCell(state_size, reuse=tf.get_variable_scope().reuse)rnn_cells = tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(num_layers)], state_is_tuple = True)outputs, current_state = tf.nn.dynamic_rnn(rnn_cells, x, initial_state=rnn_tuple_state)
阅读全文
0 0
原创粉丝点击