『目标检测』Top-N 指标计算方法

一、图像分类性能评估指标(概念介绍)

Top-1 & Top5: 这两个标准主要用于图像分类任务中

Top-1 error rate: 对一张图片,若概率最大的是正确答案,则认为分类正确,否则错误;用 argmax 从网络输出取到的预测 index 与真实 index 的准确率。

Top-5 error rate: 对一张图片,若概率前五的预测中包含正确答案,则认为分类正确,否则错误;

二、问题分析

1. 针对 Top-1 的准确率: 直接通过 argmax 就可以了

import numpy as np
lists = np.array([0.4,0.2,0.3,0.1])
index = np.argmax(lists)
score = lists[index]

2. 针对 Top-N(N>1) 的准确率: 无法使用 argmax 进行解决了,可以考虑利用 Numpy 中的 argsort

np.argmax 的功能就是对 list 从小到大进行排序,最后输出排序过后每个元素本来的下标。

import numpy as np
lists = np.array([0.4,0.2,0.3,0.1])
indexs = np.argsort(lists)
print(indexs)		# [3 1 2 0]

这个怎么应用到 Top-N 计算中呢?其实就很容易了,可以利用 argsort 取得排好序元素的下标,再通过下标找到对应的概率值即可:以 Top-3 指标举例

import numpy as np

lists = np.array([0.4,0.2,0.3,0.1])

def get_top_n(lists,n):
    sort_index = np.argsort(lists)
    n_index = sort_index[-n:]	# 因为是按照概率从大到小取 n 个
    indexs = []
    scores = []
    for index in reversed(n_index):	# 从大到小取,所以通过 reversed() 倒置一下
        indexs.append(index)
        scores.append(lists[index])
    return(indexs,socres)
 
indexs,scores = get_top_n(lists, 3)
print(indexs, scores)	# [0, 2, 1] [0.4, 0.3, 0.2]
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

libo-coder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值