gpt4 book ai didi

machine-learning - TensorFlow:在另一个 LSTM 之上的 LSTM

转载 作者:行者123 更新时间:2023-11-30 08:36:25 26 4
gpt4 key购买 nike

没什么好说的作为介绍:我想在 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的线

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

最佳答案

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

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

# ...
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)
# ...

关于machine-learning - TensorFlow:在另一个 LSTM 之上的 LSTM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38922063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com