Neural network 运行两个RNN的Tensorflow:变量hidden/RNN/LSTMCell/W_0已存在
我试图同时运行两个rnn,并通过为每个Neural network 运行两个RNN的Tensorflow:变量hidden/RNN/LSTMCell/W_0已存在,neural-network,tensorflow,recurrent-neural-network,Neural Network,Tensorflow,Recurrent Neural Network,我试图同时运行两个rnn,并通过为每个rnn\u cell.LSTMCell定义两个变量范围,将它们的输出连接在一起。为什么我收到这个变量已经存在错误 ValueError:隐藏的变量/RNN/LSTMCell/W_0已存在, 不允许。您的意思是在VarScope中设置reuse=True吗 为什么它是“隐藏的/RNN/LSTMCell/W_0”而不是“隐藏的/向前的\u lstm_单元/RNN/LSTMCell/W_0” 只需使用tf.variable\u scope而不是tf.name\u
rnn\u cell.LSTMCell
定义两个变量范围,将它们的输出连接在一起。为什么我收到这个变量已经存在错误
ValueError:隐藏的变量/RNN/LSTMCell/W_0已存在,
不允许。您的意思是在VarScope中设置reuse=True吗
为什么它是“隐藏的/RNN/LSTMCell/W_0”而不是“隐藏的/向前的\u lstm_单元/RNN/LSTMCell/W_0”
只需使用
tf.variable\u scope
而不是tf.name\u scope
tf.name\u scope
不会为使用tf.get\u variable()创建的变量添加前缀
只需使用tf.variable\u scope
而不是tf.name\u scope
tf.name\u scope
不会向使用tf.get\u variable()创建的变量添加前缀
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
)