ValueError: Trying to share variable rnn/multi_rnn_cell/cell_0/basic_lstm_cell/kernel

前端 未结 4 1199
予麋鹿
予麋鹿 2020-12-14 18:01

This it the code:

X = tf.placeholder(tf.float32, [batch_size, seq_len_1, 1], name=\'X\')
labels = tf.placeholder(tf.float32, [None, alpha_size], name=\'label         


        
4条回答
  •  清歌不尽
    2020-12-14 18:26

    I guess it's because your RNN cells on each of your 3 layers share the same input and output shape.

    On layer 1, the input dimension is 513 = 1(your x dimension) + 512(dimension of the hidden layer) for each timestamp per batch.

    On layer 2 and 3, the input dimension is 1024 = 512(output from previous layer) + 512 (output from previous timestamp).

    The way you stack up your MultiRNNCell probably implies that 3 cells share the same input and output shape.

    I stack up MultiRNNCell by declaring two separate types of cells in order to prevent them from sharing input shape

    rnn_cell1 = tf.contrib.rnn.BasicLSTMCell(512)
    run_cell2 = tf.contrib.rnn.BasicLSTMCell(512)
    stack_rnn = [rnn_cell1]
    for i in range(1, 3):
        stack_rnn.append(rnn_cell2)
    m_rnn_cell = tf.contrib.rnn.MultiRNNCell(stack_rnn, state_is_tuple = True)
    

    Then I am able to train my data without this bug. I'm not sure whether my guess is correct, but it works for me. Hope it works for you.

提交回复
热议问题