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

sdr*_*abb 8 python tensorflow

我需要计算此问题中描述的mAP,以使用Tensorflow进行对象检测

平均精度(AP)是用于排名集的典型性能指标。AveragePrecision定义为范围S中每个真实正值TP之后精度分数的平均值。给定范围S = 7,并且有一个排名列表(增益向量)G = [1,1,0,1,1,0 ,0,1,1,0,1,0,0,..]其中1/0分别表示与相关/不相关项目相关的收益:

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

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

我得到了5个单热张量与预测:

prediction_A 
prediction_B
prediction_C 
prediction_D 
prediction_E 
Run Code Online (Sandbox Code Playgroud)

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

00100
01000
00001
00010
00010
Run Code Online (Sandbox Code Playgroud)

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

y_A
y_B
y_C
y_D
y_E
Run Code Online (Sandbox Code Playgroud)

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

我发现了此功能, 但我无法使用它,因为我有多维矢量。

我还编写了一个计算AP的python函数,但它不使用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
Run Code Online (Sandbox Code Playgroud)

cin*_*nqS 5

我认为您可能需要这个:

tf.metrics.average_precision_at_k
Run Code Online (Sandbox Code Playgroud)

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

以下是参考链接

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

实现了此处定义的AP @ K指标:

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

顺便说一句,如果您需要Tensorflow中的指标,则首先应在其正式文档中进行搜索。这是所有已实施指标的列表

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

干杯

  • 我认为这不是一个完整的答案,mAP 与您提到的不同,因为我们需要牢记 IOU。 (3认同)