小编zda*_*ght的帖子

无法使用MultiRNNCell和dynamic_rnn堆叠LSTM

我正在尝试建立一个多变量时间序列预测模型.我按照以下教程进行温度预测.http://nbviewer.jupyter.org/github/addfor/tutorials/blob/master/machine_learning/ml16v04_forecasting_with_LSTM.ipynb

我想通过使用以下代码将他的模型扩展到多层LSTM模型:

cell = tf.contrib.rnn.LSTMCell(hidden, state_is_tuple=True)  
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers,state_is_tuple=True)  
output, _ = tf.nn.dynamic_rnn(cell=cell, inputs=features, dtype=tf.float32)
Run Code Online (Sandbox Code Playgroud)

但我有一个错误说:

ValueError:尺寸必须相等,但对于输入形状为'rnn/while/rnn/multi_rnn_cell/cell_0/cell_0/lstm_cell/MatMul_1'(op:'MatMul')的值为256和142:[?,256],[142,512] .

当我尝试这个时:

cell = []
for i in range(num_layers):
    cell.append(tf.contrib.rnn.LSTMCell(hidden, state_is_tuple=True))
cell = tf.contrib.rnn.MultiRNNCell(cell,state_is_tuple=True)
output, _ = tf.nn.dynamic_rnn(cell=cell, inputs=features, dtype=tf.float32)
Run Code Online (Sandbox Code Playgroud)

我没有这样的错误,但预测真的很糟糕.

我定义 hidden=128.

features = tf.reshape(features, [-1, n_steps, n_input])具有(?,1,14)单层表壳的形状.

我的数据看起来像这样 x.shape=(594,14), y.shape=(591,1)

我很困惑如何在张量流中堆叠LSTM单元.我的张量流版本是0.14.

multi-layer lstm tensorflow

6
推荐指数
1
解决办法
2712
查看次数

标签 统计

lstm ×1

multi-layer ×1

tensorflow ×1