检测评价函数 intersection-over-union ( IOU )

1、概念

在目标检测的评价体系中,有一个参数叫做 IoU ,简单来讲就是模型产生的目标窗口和原来标记窗口的交叠率。具体我们可以简单的理解为: 即检测结果(DetectionResult)Ground Truth 的交集比上它们的并集,即为检测的准确率 IoU :

IOU=DetectionResultGroundTruthDetectionResultGroundTruth I O U = D e t e c t i o n R e s u l t ⋂ G r o u n d T r u t h D e t e c t i o n R e s u l t ⋃ G r o u n d T r u t h

如下图所示:GT = GroundTruth; DR = DetectionResult;
黄色边框框起来的是:

GTDR G T ⋂ D R

绿色框框起来的是:
GTDR G T ⋃ D R

应该够详细了,上幅图直观些。当然最理想的情况就是 DR 与 GT 完全重合,即

IoU=1 I o U = 1

下面附上图例说明,及 IOU 的python实现,已经测试无误,自行取用。

这里写图片描述

原图:
这里写图片描述

# -*- coding: utf-8 -*-
"""
Created on Sun Aug 07 14:26:51 2016

@author: Eddy_zheng
"""

def IOU(Reframe,GTframe):
    """
    自定义函数,计算两矩形 IOU,传入为均为矩形对角线,(x,y)  坐标。
    """
    x1 = Reframe[0]
    y1 = Reframe[1]
    width1 = Reframe[2]-Reframe[0]
    height1 = Reframe[3]-Reframe[1]

    x2 = GTframe[0]
    y2 = GTframe[1]
    width2 = GTframe[2]-GTframe[0]
    height2 = GTframe[3]-GTframe[1]

    endx = max(x1+width1,x2+width2)
    startx = min(x1,x2)
    width = width1+width2-(endx-startx)

    endy = max(y1+height1,y2+height2)
    starty = min(y1,y2)
    height = height1+height2-(endy-starty)

    if width <=0 or height <= 0:
        ratio = 0 # 重叠率为 0 
    else:
        Area = width*height # 两矩形相交面积
        Area1 = width1*height1
        Area2 = width2*height2
        ratio = Area*1./(Area1+Area2-Area)
    # return IOU
    return ratio,Reframe,GTframe
阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 36
    点赞
  • 108
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hanranV

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

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

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

打赏作者

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

抵扣说明:

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

余额充值