title: Restoring saved TensorFlow model to evaluate on test set
body: <p>I have seen a few <a href="https://stackoverflow.com/questions/34982492/restoring-tensorflow-model">posts</a> on restoring <code>TF</code> models and the <code>Google</code> doc page on <a href="https://www.tensorflow.org/how_tos/meta_graph/" rel="nofollow noreferrer">exporting graphs</a> but I think I am missing something.</p>
  
  <p>I use the code in this <a href="https://gist.github.com/autojazari/13e81462cc736c5772277f26249e61f1" rel="nofollow noreferrer">Gist</a> to save the model along with this utils file to which <a href="https://gist.github.com/autojazari/8b282d58a38ff6f920e413d82bbefcbd" rel="nofollow noreferrer">defines</a> the model</p>
  
  <p>Now I would like to restore it and run in a previously unseen test data as follows:</p>
  
  <pre><code>def evaluate(X_data, y_data):
      num_examples = len(X_data)
      total_accuracy = 0
      total_loss = 0
      sess = tf.get_default_session()
      acc_steps = len(X_data) // BATCH_SIZE
      for i in range(acc_steps):
          batch_x, batch_y = next_batch(X_val, Y_val, BATCH_SIZE)
  
          loss, accuracy = sess.run([loss_value, acc], feed_dict={
                  images_placeholder: batch_x,
                  labels_placeholder: batch_y,
                  keep_prob: 0.5
                  })
          total_accuracy += (accuracy * len(batch_x))
          total_loss += (loss * len(batch_x))
      return (total_accuracy / num_examples, total_loss / num_examples)
  
  ## re-execute the code that defines the model
  
  # Image Tensor
  images_placeholder = tf.placeholder(tf.float32, shape=[None, 32, 32, 3], name='x')
  
  gray = tf.image.rgb_to_grayscale(images_placeholder, name='gray')
  
  gray /= 255.
  
  # Label Tensor
  labels_placeholder = tf.placeholder(tf.float32, shape=(None, 43), name='y')
  
  # dropout Tensor
  keep_prob = tf.placeholder(tf.float32, name='drop')
  
  # construct model
  logits = inference(gray, keep_prob)
  
  # calculate loss
  loss_value = loss(logits, labels_placeholder)
  
  # training
  train_op = training(loss_value, 0.001)
  
  # accuracy
  acc = accuracy(logits, labels_placeholder)
  
  with tf.Session() as sess:
      loader = tf.train.import_meta_graph('gtsd.meta')
      loader.restore(sess, tf.train.latest_checkpoint('./'))
      sess.run(tf.initialize_all_variables())   
      test_accuracy = evaluate(X_test, y_test)
      print("Test Accuracy = {:.3f}".format(test_accuracy[0]))
  </code></pre>
  
  <p>I'm getting a test accuracy of only <em>3%</em>.  However If I don't close the Notebook and run the test code immediately after training the model, I get a <em>95%</em> accuracy.  </p>
  
  <p>This leads me to believe I'm not loading the model correctly?</p>