def biLSTM(data, n_steps):
n_hidden= 24
data = tf.transpose(data, [1, 0, 2])
# Reshape to (n_steps*batch_size, n_input)
data = tf.reshape(data, [-1, 300])
# Split to get a list of 'n_steps' tensors of shape (batch_size, n_input)
data = tf.split(0, n_steps, data)
lstm_fw_cell = tf.nn.rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0)
# Backward direction cell
lstm_bw_cell = tf.nn.rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0)
outputs, _, _ = tf.nn.bidirectional_rnn(lstm_fw_cell, lstm_bw_cell, data, dtype=tf.float32)
return outputs, n_hidden
私のコードでは、この関数を2回呼び出して2つの双方向LSTMを作成しています。それから、変数を再利用するという問題があります。これを解決するにはTensorflowの可変範囲の問題
ValueError: Variable lstm/BiRNN_FW/BasicLSTMCell/Linear/Matrix already exists, disallowed. Did you mean to set reuse=True in VarScope?
私は、これは新しい問題に
ValueError: Variable lstm/BiRNN_FW/BasicLSTMCell/Linear/Matrix does not exist, disallowed. Did you mean to set reuse=None in VarScope?
を率いwith tf.variable_scope('lstm', reuse=True) as scope:
内の関数でLSTM定義を追加これに対する解決策を支援してください。
ありがとうございます@ mad-wombat。出来た。私は第二の選択肢を試しました。 –
@Mad Wombat私も同様の問題がhttps://stackoverflow.com/questions/47657157/variables-of-tensorflow-generate-error-in-a-loop/47718155?noredirect=1#comment82519963_47718155にあります見た目と答え。 – khan