张量流中的平均精度(mAP)

Mean average precision (mAP) in tensorflow

我需要使用 Tensorflow目标检测 计算此 中描述的 mAP.

平均精度 (AP) 是用于排名集的典型性能度量。 AveragePrecision 定义为范围 S 中每个真阳性 TP 之后的精度分数的平均值。给定范围 S = 7,以及排名列表(增益向量)G = [1,1,0,1,1,0 ,0,1,1,0,1,0,0,..] 其中 1/0 表示与 relevant/non-相关项目相关的增益,分别为:

AP = (1/1 + 2/2 + 3/4 + 4/5) / 4 = 0.8875.

平均精度 (mAP):一组查询的平均精度值的平均值。

我得到了 5 个 One-Hot 张量与预测:

prediction_A 
prediction_B
prediction_C 
prediction_D 
prediction_E 

其中单个预测张量具有此结构(例如 prediction_A):

00100
01000
00001
00010
00010

然后我得到了正确的标签(one-hot)张量,具有相同的结构:

y_A
y_B
y_C
y_D
y_E

我想使用 tensorflow 计算 mAP,因为我想总结一下,我该怎么做?

我找到了这个 function 但我不能使用它,因为我有一个多维向量。

我还编写了一个 python 函数来计算 AP 但它不使用 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

我想你可能需要这个:

tf.metrics.average_precision_at_k

此方法采用标签和预测来计算您提到的 AP@K

下面是引用的链接

https://www.tensorflow.org/api_docs/python/tf/metrics/average_precision_at_k

which implemented AP@K metric defined here:

https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval)#Average_precision

BTW, if you need a metric in Tensorflow, firstly you should search inside their official documents. Here is a list of all implemented metrics

https://www.tensorflow.org/api_docs/python/tf/metrics

干杯