ここで私のコードはテンソルフローです。私はBi-LSTMを定義しました。特定のタスクでグラフをループする必要があります。スコープ変数でreuse = Trueを設定していますが、コードの下に記載されているエラーが生成されます。TensorFlow再利用可変スコープ
for run in range(0, 2):
with tf.variable_scope("LSTM", reuse= True) as scope:
def LSTM(input_data):
LSTM_cell_fw= tf.contrib.rnn.BasicLSTMCell(num_units= hidden_size)
LSTM_cell_bw= tf.contrib.rnn.BasicLSTMCell(num_units= hidden_size)
output, states = tf.nn.bidirectional_dynamic_rnn(LSTM_cell_fw, LSTM_cell_bw, inputs= input_data, dtype=tf.float32)
output_1= output[0]
output_2= output[1]
output_1= output_1[-1, -1, :]
output_1= tf.reshape(output_1, shape= (1, hidden_size))
output_2= output_2[-1, -1, :]
output_2= tf.reshape(output_2, shape= (1, hidden_size))
fin_output= tf.concat((output_1, output_2), axis=1)
return fin_output
とエラーになります:ValueErrorを:可変bidirectional_rnn/FW/basic_lstm_cell /カーネルはすでに禁止さ、存在しています。 VarScopeでreuse = Trueを設定することを意味しましたか?もともとで定義:
ファイル "alpha-rep.py"、ライン65は、LSTM 出力で、= tf.nn.bidirectional_dynamic_rnn(LSTM_cell_fw、LSTM_cell_bw、入力= INPUT_DATA、DTYPE = tf.float32) ファイル」を述べて変数を再利用する アウト= LSTM(INPUT_DATA)
ありがとうございました。たとえば、グラフが動作している最初の時間(run = 0)を意味します。再利用はfalseになります。実行したときに0を返します。 – Maz
それは完璧なおかげで働いた – Maz
ようこそ! – nessuno