作为介绍,我没有太多要说的:我想在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? 使用outputs2、states2指向直线
重置图一点帮助都没有。如果需要任何额外的信息来帮助解决这个问题,我将很乐意提供。
发布于 2016-08-13 00:46:35
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)
# ...https://stackoverflow.com/questions/38922063
复制相似问题