2016-10-11 6 views
1

2つのRNNを同時に実行し、それぞれの出力を連結して、rnn_cell.LSTMCellの2つの変数スコープを定義しようとしています。なぜこの変数は既に存在していますか?2つのRNNを実行しているTensorflow:変数hidden/RNN/LSTMCell/W_0は既に存在します

ValueError: Variable hidden/RNN/LSTMCell/W_0 already exists, disallowed. Did you mean to set reuse=True in VarScope?

なぜそれが "隠し/ RNN/LSTMCell/W_0" ではない "隠し/ forward_lstm_cell/RNN/LSTMCell/W_0" です???

with tf.variable_scope('hidden', reuse=reuse): #reuse=None during training 
     with tf.variable_scope('forward_lstm_cell'): 
      lstm_fw_cell = tf.nn.rnn_cell.LSTMCell(num_units=self.num_hidden, use_peepholes=False, 
               initializer=tf.random_uniform_initializer(-0.003, 0.003), 
               state_is_tuple=True) 
      if not reuse: 
       lstm_fw_cell = tf.nn.rnn_cell.DropoutWrapper(cell=lstm_fw_cell, input_keep_prob=0.7) 

     with tf.variable_scope('backward_lstm_cell'): 
      lstm_bw_cell = tf.nn.rnn_cell.LSTMCell(num_units=self.num_hidden, use_peepholes=False, 
               forget_bias=0.0, 
               initializer=tf.random_uniform_initializer(-0.003, 0.003), 
               state_is_tuple=True) 
      if not reuse: 
       lstm_bw_cell = tf.nn.rnn_cell.DropoutWrapper(cell=lstm_bw_cell, input_keep_prob=0.7) 

     with tf.name_scope("forward_lstm"): 
      outputs_fw, output_states_fw = tf.nn.dynamic_rnn(
       cell=lstm_fw_cell, 
       inputs=embed_inputs_fw, 
       dtype=tf.float32, 
       sequence_length=self.seq_len_l 
       ) 

     with tf.name_scope("backward_lstm"): 
      outputs_bw, output_states_bw = tf.nn.dynamic_rnn(
       cell=lstm_bw_cell, 
       inputs=embed_inputs_bw, 
       dtype=tf.float32, 
       sequence_length=self.seq_len_r 
       ) 

答えて

3

だけtf.variable_scopeの代わりtf.name_scopeを使用しています。 tf.name_scopeは、作成された変数に接頭辞を追加しません。with tf.get_variable()

+0

ありがとうございました!それは今働く。 – Blue482

関連する問題