Tensorflow - Using batching to make predictions
<p>I'm attempting to make predictions using a trained convolutional neural network, slightly modified from the example in the example expert tensorflow tutorial. I have followed the instructions at <a href="https://www.tensorflow.org/versions/master/how_tos/reading_data/index.html" rel="nofollow">https://www.tensorflow.org/versions/master/how_tos/reading_data/index.html</a> to read data from a CSV file. </p>

<p>I have trained the model and evaluated its accuracy. I then saved the model and loaded it into a new python script for making predictions. Can I still use the batching method detailed in the link above or should I use <code>feed_dict</code> instead? Most tutorials I've seen online use the latter. </p>

<p>My code is shown below, I have essentially duplicated the code for reading from my training data, which was stored as lines within a single .csv file. Conv_nn is simply a class that contains the convolutional neural network detailed in the expert MNIST tutorial. Most of the content is probably not very useful except for the part where I run the graph. </p>

<p><strong>I suspect I have badly mixed up training and prediction - I'm not sure if the test images are being fed to the prediction operation correctly or if it is valid to use the same batch operations for both datasets.</strong> </p>

<pre><code>filename_queue =  tf.train.string_input_producer(["data/test.csv"],num_epochs=None)

reader = tf.TextLineReader()
key, value = reader.read(filename_queue)

# Defaults force key value and label to int, all others to float.
record_defaults = [[1]]+[[46]]+[[1.0] for i in range(436)]
# Reads in a single row from the CSV and outputs a list of scalars.
csv_list = tf.decode_csv(value, record_defaults=record_defaults)
# Packs the different columns into separate feature tensors.
location = tf.pack(csv_list[2:4])
bbox = tf.pack(csv_list[5:8])
pix_feats = tf.pack(csv_list[9:])
onehot = tf.one_hot(csv_list[1], depth=98)
keep_prob = 0.5


# Creates batches of images and labels.
image_batch, label_batch = tf.train.shuffle_batch(
    [pix_feats, onehot],
    batch_size=50,num_threads=4,capacity=50000,min_after_dequeue=10000)

# Creates a graph of variables and operation nodes.
nn = Conv_nn(x=image_batch,keep_prob=keep_prob,pixels=33*13,outputs=98)

# Launch the default graph.
with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())
    saver.restore(sess, 'model1.ckpt')
    print("Model restored.")

    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess,coord=coord)

    prediction=tf.argmax(nn.y_conv,1)

    pred = sess.run([prediction])

    coord.request_stop()
    coord.join(threads)
</code></pre>

<p>Does using tensorflow serving to make predictions work for you?</p>

python machine-learning tensorflow