Reputation: 61
In tensorflow the model is created with training data but i want to know how is the test data are evaluated with accuracy calculated with training data.
correct_prediction = tf.equal(tf.argmax(pred, 1),tf.argmax(y_train, 1))
# Calculate accuracy
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print "Accuracy:", accuracy.eval({x1: X_test, y1: y_test})
correct_prediction is done with training data and accuracy.eval() is used to pass test data set. Please explain how this is done.
Upvotes: 0
Views: 2278
Reputation: 28198
In TensorFlow you create a graph, where data flows between nodes, from inputs to outputs.
Let's take a simple example, MNIST. Here are the TensorFlow nodes:
images
of shape [batch_size, 28, 28, 1]
labels
of shape [batch_size, 10]
pred
, of shape [batch_size, 10]
accuracy
, shape []
(scalar)Here is the graph:
images
|
(CNN)
|
labels pred
\ |
\ |
correct_prediction
|
accuracy
The two inputs nodes are tf.placeholder
, which means that you need to manually enter values in them.
Depending on whether you are training or testing the model, you can feed:
images
and labels
with two numpy arrays X_train
and y_train
of corresponding shape, from your dataimages
and labels
with two numpy arrays X_test
and y_test
which are the test dataWith this architecture, the same graph is used both for training and testing.
The difference is that:
sess.run(train_op, feed_dict={images: X_train, labels: y_train})
sess.run(accuracy, feed_dict={images: X_test, labels: y_test})
Upvotes: 2