How to compute accuracy of CNN in TensorFlow

akshata bhat picture akshata bhat · Mar 5, 2017 · Viewed 11.4k times · Source

I am new to TensorFlow. I am doing a binary classification with my own dataset. However I do not know how to compute the accuracy. Can anyone please help me with to do this?

My classifier has 5 convolutional layers followed by 2 fully connected layers. The final FC layer has an output dimension of 2 for which I have used:

prob = tf.nn.softmax(classification_features, name="output")

Answer

Androbin picture Androbin · Mar 5, 2017

Just calculate the percentage of correct predictions:

prediction = tf.math.argmax(prob, axis=1)
equality = tf.math.equal(prediction, correct_answer)
accuracy = tf.math.reduce_mean(tf.cast(equality, tf.float32))