【问题标题】:TensorFlow: LSTM on top of another LSTMTensorFlow:在另一个 LSTM 之上的 LSTM
【发布时间】:2016-12-19 17:02:09
【问题描述】:

作为介绍就没什么好说的了:本来想在TensorFlow中把LSTM叠在另一个LSTM上,但是一直被错误阻止我不太明白,更别说单枪匹马解决了。

代码如下:

def RNN(_X, _istate, _istate_2, _weights, _biases):

    _X = tf.transpose(_X, [1, 0, 2])  
    _X = tf.reshape(_X, [-1, rozmiar_wejscia]) 
    _X = tf.matmul(_X, _weights['hidden']) + _biases['hidden']

    lstm_cell = rnn_cell.BasicLSTMCell(ukryta_warstwa, forget_bias=1.0)
    _X = tf.split(0, liczba_krokow, _X)

    outputs, states = rnn.rnn(lstm_cell, _X, initial_state=_istate)


    lstm_cell_2 = rnn_cell.BasicLSTMCell(ukryta_warstwa, forget_bias = 1.0)
    outputs2, states2 = rnn.rnn(lstm_cell_2, outputs, initial_state = _istate_2)

    return tf.matmul(outputs2[-1], _weights['out']) + _biases['out']

而我一直收到的是:

ValueError: Variable RNN/BasicLSTMCell/Linear/Matrix already exists, disallowed. Did you mean to set reuse=True in VarScope? 

指向与输出2、状态2一致

重置图表一点帮助也没有。如果需要任何其他信息来帮助解决问题,我很乐意提供。

【问题讨论】:

标签: machine-learning tensorflow deep-learning recurrent-neural-network lstm


【解决方案1】:

TensorFlow 的 RNN 代码使用"variable scopes" 来管理变量的创建和共享,在这种情况下,它无法判断您是要为第二个 RNN 创建一组新的变量,还是重用一组旧的变量。

假设您希望两个 RNN 的权重是独立的,您可以通过将每个 RNN 包装在不同名称的 with tf.variable_scope(name): 块中来解决此错误,如下所示:

# ...
with tf.variable_scope("first_lstm"):
  lstm_cell = rnn_cell.BasicLSTMCell(ukryta_warstwa, forget_bias=1.0)
  _X = tf.split(0, liczba_krokow, _X)

  outputs, states = rnn.rnn(lstm_cell, _X, initial_state=_istate)

with tf.variable_scope("second_lstm"):
  lstm_cell_2 = rnn_cell.BasicLSTMCell(ukryta_warstwa, forget_bias=1.0)
  outputs2, states2 = rnn.rnn(lstm_cell_2, outputs, initial_state=_istate_2)
# ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 2016-06-22
    • 2016-11-09
    • 1970-01-01
    • 2016-10-20
    • 2017-07-18
    相关资源
    最近更新 更多