Search code examples
tensorflowclassificationconvolution

How to compute accuracy of CNN in TensorFlow


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")

Solution

  • 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))