I need to calculate the mAP described in this question to detect an object using Tensorflow .
Medium Accuracy (AP) is a typical measure of performance used for ranked sets. AveragePrecision is defined as the average value of precision estimates after each true positive TP value in area S. Given the scale S = 7 and the ranked list (gain vector) G = [1,1,0,1,1,0, 0,1,1, 0,1,0,0, ..] where 1/0 indicate the coefficients associated with the relevant / irrelevant elements, respectively:
AP = (1/1 + 2/2 + 3/4 + 4/5) / 4 = 0.8875.
Average Average Accuracy (mAP) : The average value of average accuracy for a set of queries.
I got 5 one-line tensors with predictions:
prediction_A
prediction_B
prediction_C
prediction_D
prediction_E
where one prediction tensor has this structure (for example, prediction_A):
00100
01000
00001
00010
00010
Then I have the correct (hot) shadow labels with the same structure:
y_A
y_B
y_C
y_D
y_E
I want to calculate mAP using tensorflow , so I want to generalize this, how can I do this?
I found this function , but I can’t use it because I have a multidimensional vector.
I also write a python function that calculates AP but does not use Tensorflow
def compute_av_precision(match_list):
n = len(match_list)
tp_counter = 0
cumulate_precision = 0
for i in range(0,n):
if match_list[i] == True:
tp_counter += 1
cumulate_precision += (float(tp_counter)/float(i+1))
if tp_counter != 0:
av_precision = cumulate_precision/float(tp_counter)
return av_precision
return 0