title: How to reuse the weights in Tensorflow?
body: <p>I will call the below tensorflow code for several times. Would the weights be reused or every time it will create a new graph?</p>
  
  <pre><code>    def lstm(encoder_cell, encoder_inputs_embedded, encoder_inputs_length):
          with tf.variable_scope('lstm') as scope_bilstm:
              ((encoder_fw_outputs,
                encoder_bw_outputs),
               (encoder_fw_state,
                encoder_bw_state)) = (
                  tf.nn.bidirectional_dynamic_rnn(cell_fw=encoder_cell,
                                                  cell_bw=encoder_cell,
                                                  inputs=encoder_inputs_embedded,
                                                  sequence_length=encoder_inputs_length,
                                                  time_major=False,
                                                  dtype=tf.float32)
                  )
  
          encoder_outputs = tf.concat((encoder_fw_outputs, encoder_bw_outputs), 2)
  
          return encoder_outputs
  </code></pre>
  
  <p>Since I know it might not be reused, I tried the following code by adding an additional <code>reuse=True</code> in the <code>tf.variable_scope()</code>.</p>
  
  <pre><code>    def lstm(encoder_cell, encoder_inputs_embedded, encoder_inputs_length):
          with tf.variable_scope('lstm', reuse=True) as scope_bilstm:
              ((encoder_fw_outputs,
                encoder_bw_outputs),
               (encoder_fw_state,
                encoder_bw_state)) = (
                  tf.nn.bidirectional_dynamic_rnn(cell_fw=encoder_cell,
                                                  cell_bw=encoder_cell,
                                                  inputs=encoder_inputs_embedded,
                                                  sequence_length=encoder_inputs_length,
                                                  time_major=False,
                                                  dtype=tf.float32)
                  )
  
          encoder_outputs = tf.concat((encoder_fw_outputs, encoder_bw_outputs), 2)
  
          return encoder_outputs
  </code></pre>
  
  <p>But I got the following error,</p>
  
  <blockquote>
    <p>ValueError: Variable inner/bidirectional_rnn/fw/lstm_cell/weights does
    not exist, or was not created with tf.get_variable(). Did you mean to
    set reuse=None in VarScope?</p>
  </blockquote>
  
  <p>How can I address this error? I really appreciate it!</p>
  
  <p>What about <code>scope_bilstm.reuse_variables()</code>? I don't know where to insert that line in my program.</p>