Tensorflow: train and test in separate functions
<p>I am trying to use a Tensorflow model in two separate functions: one that trains it, and one used to test it. For example, the training function looks something like this:</p>

<pre><code>graph = tf.Graph()
with graph.as_default():
    tf_dataset = tf.placeholder(tf.float32, shape=(None, num_dims))
    ...
    weights = tf.Variable(tf.truncated_normal([num_dims, num_labels]))
    ...
    optimizer =    tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)
    prediction = tf.nn.softmax(logits)
    ...
    session = tf.Session(graph=graph)
    ...
</code></pre>

<p>The other, evaluation function would just use <code>prediction</code> with the test data, like so:</p>

<pre><code>session.run(prediction, feed_dict={tf_dataset: test_data})
</code></pre>

<p>The problem is, of course, that <code>tf_dataset</code> is not in the scope of the other function. I am fine with returning <code>session</code> and <code>prediction</code> from the training function, but having to share every single placeholder with the evaluation code seems a bit lame.</p>

<p>Is there a way to get the references somehow, from the session or the graph? Also, are there any good practices on how to separate training and evaluation code in Tensorflow?</p>