Image Classification

top-k accuracy

Top-k accuracy measures how often the correct class appears among the k highest-scoring predictions a model makes for an image, rather than demanding that it be the single highest. For k equal to 1 this is ordinary accuracy: the prediction counts as correct only if the model's top choice matches the label. For k equal to 5 the prediction counts as correct if the true class is anywhere in the model's five best guesses.

It became the standard ImageNet reporting metric precisely because ImageNet has 1000 fine and often overlapping classes, including many breeds of dog and dozens of similar vehicles, and a single image can plausibly contain several labellable objects while carrying only one ground-truth label. Top-5 accuracy forgives a model that ranks the right answer second or third behind a genuinely reasonable alternative, giving a less brittle picture of recognition quality than top-1 alone.

Compute top-k by sorting the per-class scores in descending order, taking the first k class indices, and checking whether the true label is in that set; then average the 0/1 outcome over the test set. Always report which k you used, because top-1 and top-5 numbers are not comparable. Note also that top-k says nothing about how confident or well calibrated the scores are: a model can have excellent top-5 accuracy and badly miscalibrated probabilities.

On ImageNet a well-trained ResNet-50 reaches roughly 76 percent top-1 and 93 percent top-5 accuracy; the 17-point gap means that in many of its top-1 mistakes the true class was still among its next four guesses.

Also called
top-1 accuracytop-5 accuracy