How to use a previously trained model to get labels of images - TensorFlow
<p>After training a model (according to the <a href="https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html" rel="nofollow">mnist tutorial</a>), and saving it using this code:</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 succeeded to load the model and test it with an already exist database, as follows:</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 succeed to load and test the model, <strong>I don't know how to get y'</strong> array (the model's predictions for the database images).</p>

<p>I scanned the web and found a lot of answers for this question, but I couldn't project those answers for this particular case (e.g. <a href="http://stackoverflow.com/questions/37578876/how-to-feed-cifar10-trained-model-with-my-own-image-and-get-label-as-output">this answer</a> that given about the CIFAR10 tutorial, which really different from the MNIST tutorial).</p>

<p>A detailed answer will highly appreciated (I'm new with tensorflow and still learning the terminology). Thanks a lot for your help!</p>

<p>Another option to what lejlot just answered(and this option is primarily for learning and understanding  what the network is doing ) could be:You can make predictions  using feedforward using the weights and biases that your network already learned that means that al the computations you defined in your  "BUILD AND DEFINE ALL THE LAYERS" should be applied to  a new dataset ,for example asuming that your network is of the shape inputs-> relu layer -> softmax layer. You would compute:</p>

<pre><code>relu_layer_oututs = tf.nn.relu(tf.matmul(input_data,weights_layer1)+biases_layer1 );
prediction = tf.nn.softmax(tf.matmul(relu_layer_outputs,weights_layer2)+biases_layer2);
</code></pre>

python python-2.7 machine-learning neural-network tensorflow