3

紹介としてはあまり言いません:私はTensorFlowの別のLSTMにLSTMを積み重ねたいと思いますが、誤って停止され続けています。ここで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'] 

そして、何私が受信し続けることです。

outputs2と行を指し示す
ValueError: Variable RNN/BasicLSTMCell/Linear/Matrix already exists, disallowed. Did you mean to set reuse=True in VarScope? 

、states2

グラフは、わずかなビットには役立ちませんリセット。問題の解決に役立つ追加情報が必要な場合は、喜んで提供します。

+0

またMultiRNNCellを見てLSTMセルを積み重ねることができ、要件を満たすことができます。https://www.tensorflow.org/versions/r0.9/api_docs/python/rnn_cell.html#MultiRNNCell –

+0

[Tensorflow: _scope](http://stackoverflow.com/questions/39665702/tensorflow-value-error-with-variable-scope) –

答えて

2

TensorFlowのRNNコードは"variable scopes"を使用して変数の作成と共有を管理します。この場合、2番目のRNNの新しい変数セットを作成するか、古い変数セットを再利用するかを判断できません。

次のように、次の2つのRNNの重みが独立することにしたいことを、あなたは違った名前のwith tf.variable_scope(name):ブロック内の各RNNをラップすることにより、このエラーに対処することができますと仮定:

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

ありがとう、それは働いた;) – user3132736

関連する問題