MultiRNN and static_rnn error: Dimensions must be equal, but are 256 and 129

前端 未结 1 1154
旧巷少年郎
旧巷少年郎 2021-01-21 00:25

I want to build an LSTM network with 3 Layers. Here\'s the code:

num_layers=3
time_steps=10
num_units=128
n_input=1
learning_rate=0.001
n_classes=1
...

x=tf.pla         


        
相关标签:
1条回答
  • 2021-01-21 01:27

    You should not reuse the same cell for the first and deeper layers, because their inputs are different, hence kernel matrices are different. Try this:

    # Extra function is for readability. No problem to inline it.
    def make_cell(lstm_size):
      return tf.nn.rnn_cell.BasicLSTMCell(lstm_size, state_is_tuple=True)
    
    network = rnn_cell.MultiRNNCell([make_cell(num_units) for _ in range(num_layers)], 
                                    state_is_tuple=True)
    
    0 讨论(0)
提交回复
热议问题