上一章:深度篇——图像处理的一些方法(一) 关于 图像处理的三个层次 与 selective search
下一章:深度篇——图像处理的一些方法(三) 细说 HOG 特征 与 bag-of-word
本小节,细说 性能评估 IOU 和 GIOU,下一小节细说 HOG 特征 与 bag-of-word
GIOU 论文地址:Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression
性能评估
自然地,通过计算得到的包含物体的 bounding boxes 与 ground true (真实情况) 的窗口重叠越多,那么性能就越好。
三. IOU (Instersectiou Over Union, IOU)
1. IOU 是一种测量在特定数据集中检测相应物体准确度的一个标准。
2. IOU 的计算公式:
:为对于每个固定的类别 C,每个 ground true (真实情况) 表示为 ,其中
:为每个 bounding box,其中
其实, 的面积比。
IOU 的 loss为:
3. IOU 的 python 代码
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
# ============================================
# @Time : 2020/02/01 16:04
# @Author : WanDaoYi
# @FileName : bbox_iou.py
# ============================================
import numpy as np
# IOU
def bboxes_iou(boxes1, boxes2):
boxes1 = np.array(boxes1)
boxes2 = np.array(boxes2)
# 计算 面积
boxes1_area = (boxes1[..., 2] - boxes1[..., 0]) * (boxes1[..., 3] - boxes1[..., 1])
boxes2_area = (boxes2[..., 2] - boxes2[..., 0]) * (boxes2[..., 3] - boxes2[..., 1])
# 交集的 左上角坐标
left_up = np.maximum(boxes1[..., :2], boxes2[..., :2])
# 交集的 右下角坐标
right_down = np.minimum(boxes1[..., 2:], boxes2[..., 2:])
# 计算交集矩形框的 high 和 width
inter_section = np.maximum(right_down - left_up, 0.0)
# 两个矩形框的 交集 面积
inter_area = inter_section[..., 0] * inter_section[..., 1]
# 两个矩形框的并集面积
union_area = boxes1_area + boxes2_area - inter_area