Top5 vs Top1 accuracy

In this article, we have explored the differences between Top5 and Top1 accuracy measurements. Both are frequently used with Machine Learning models.

Top5 vs Top1 accuracy

Following table summarizes the differences between Top5 and Top1 accuracy:

Top5 vs Top1 accuracy
Higher valueHighLow
# of predictions
Strict checkLess strictMore strict

Following is a code snippet in TensorFlow Python which calculates both Top1 and Top5 accuracy which will show that calculating both is similar with minor change:

predictions =,
                     {input_tensor: np_images})
elapsed_time = time.time() - start_time
accuracy1 = tf.reduce_sum(
      targets=tf.constant(np_labels), k=1), tf.float32))

accuracy5 = tf.reduce_sum(
      targets=tf.constant(np_labels), k=5), tf.float32))
np_accuracy1, np_accuracy5 =[accuracy1, accuracy5])
total_accuracy1 += np_accuracy1
total_accuracy5 += np_accuracy5
print("Iteration time: %0.4f ms" % elapsed_time)
print("Processed %d images. (Top1 accuracy, Top5 accuracy) = (%0.4f, %0.4f)" \
  % (num_processed_images, total_accuracy1/num_processed_images,

With this article at OpenGenus, you must have the complete idea of the differences between Top1 and Top5 accuracy.