title: How to use tf.reset_default_graph()
body: <p>Whenever I try to use <code>tf.reset_default_graph()</code>, I get this error: <code>IndexError: list index out of range</code> or ``. At which part of my code should I use this? When should I be using this?</p>
  
  <p>Edit:</p>
  
  <p>I updated the code, but the error still occurs.</p>
  
  <pre class="lang-py prettyprint-override"><code>def evaluate():
      with tf.name_scope("loss"):
          global x # x is a tf.placeholder()
          xentropy = tf.nn.softmax_cross_entropy_with_logits(labels=y, logits=neural_network(x))
          loss = tf.reduce_mean(xentropy, name="loss")
  
      with tf.name_scope("train"):
          optimizer = tf.train.AdamOptimizer()
          training_op = optimizer.minimize(loss)
  
      with tf.name_scope("exec"):
          with tf.Session() as sess:
              for i in range(1, 2):
                  sess.run(tf.global_variables_initializer())
                  sess.run(training_op, feed_dict={x: np.array(train_data).reshape([-1, 1]), y: label})
                  print "Training " + str(i)
                  saver = tf.train.Saver()
                  saver.save(sess, "saved_models/testing")
                  print "Model Saved."
  
  
  def predict():
      with tf.name_scope("predict"):
          tf.reset_default_graph()
          with tf.Session() as sess:
              saver = tf.train.import_meta_graph("saved_models/testing.meta")
              saver.restore(sess, "saved_models/testing")
              output_ = tf.get_default_graph().get_tensor_by_name('output_layer:0')
              print sess.run(output_, feed_dict={x: np.array([12003]).reshape([-1, 1])})
  
  
  def main():
      print "Starting Program..."
      evaluate()
      writer = tf.summary.FileWriter("mygraph/logs", tf.get_default_graph())
      predict()
  </code></pre>
  
  <p>If I remove the tf.reset_default_graph() from the updated code, I get this error:  <code>ValueError: cannot add op with name hidden_layer1/kernel/Adam as that name is already used</code></p>
  
  <p>From my current understanding, tf.reset_default_graph() removes all graphs, hence I avoided the error I mention above(<code>ValueError: cannot add op with name hidden_layer1/kernel/Adam as that name is already used</code>)</p>