title: How to use a previously trained model to get labels of images - TensorFlow
body: <p>I trained a model (per the <a href="https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html" rel="nofollow noreferrer">MNIST tutorial</a>) and saved it:</p>
  
  <pre><code>saver = tf.train.Saver()
  save_path = saver.save(sess,'/path/to/model.ckpt')
  </code></pre>
  
  <p>I want to use the saved model in order to find labels for a new batch of images. I load the model and test it with a database:</p>
  
  <pre><code># load MNIST data
  folds = build_database_tuple.load_data(data_home_dir='/path/to/database')
  
  # starting the session. using the InteractiveSession we avoid build the entiee comp. graph before starting the session
  sess = tf.InteractiveSession()
  
  # start building the computational graph
  ...
  
  BUILD AND DEFINE ALL THE LAYERS
  
  ...
  
  y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
  
  # TRAIN AND EVALUATION:
  cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_conv), reduction_indices=[1]))
  train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
  correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))
  accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  
  
  sess.run(tf.initialize_all_variables())
  saver = tf.train.Saver()
  # Restore variables from disk.
  savepath = '/path/to/model.ckpt'
  saver.restore(sess, save_path=savepath)
  print("Model restored.")
  
  print("test accuracy %g"%accuracy.eval(feed_dict={x: folds.test.images, y_: folds.test.labels, keep_prob: 1.0}))
  </code></pre>
  
  <p>Although I can load and test the model, how do I get the y' array that contains the predictions for the database images?</p>
  
  <p>I scanned the web and found a lot of answers for this question, but I couldn't fit those answers to this particular case. For example, I found <a href="https://stackoverflow.com/questions/37578876/how-to-feed-cifar10-trained-model-with-my-own-image-and-get-label-as-output">this answer</a>  about the CIFAR10 tutorial but it's very different from the MNIST tutorial.</p>