· Calculation method of TopN index

1. Concept introduction

In image classification, we can often see TopN accuracy rate (or time error rate), such as top-1 and top-5.

So what does this TopN mean? First of all, top-1 accuracy is best understood as the accuracy of predicted index and real index obtained from network output by argmax.

Top-5 Accuracy rate refers to the comparison between the maximum five indexes of prediction probability obtained from the network output and the real indexes. If any one of the five indexes is successfully compared, the prediction is correct. Similarly, top-3 refers to the three indexes with the highest probability.

 

2. Problem analysis

It can be found that the accuracy of top-1 is easily calculated by using argmax directly.

import numpy as np

lists = np.array([0.4.0.2.0.3.0.1])

index = np.argmax(lists)

score = lists[index]
Copy the code

Argmax cannot be used if it is greater than 1, but there is an argsort in Numpy that helps us.

The np.argmax function is to sort the list from smallest to largest and print the original subscript of each sorted element. Here’s a code to explain:

Copy the code