numpy实现GIOU代码

这篇博客介绍了如何利用numpy来实现GIOU(Generalized Intersection over Union),在目标检测任务中用于衡量预测框与真实框的匹配程度。博主提供了具体的代码实现,并提到在处理不同数量的预测框和ground truth框时的处理方法,以及如何计算每类的GIOU和平均GIOU。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

笔者使用numpy实现了GIOU,废话不多说,直接贴上代码:

import numpy as np
def GIOU (boxes1 , boxes2 ):
    "calculate GIOU  "
    '''
    boxes1 shape : shape (n, 4)
    boxes2 shape : shape (k, 4)
    gious: shape (n, k)       
    '''
    IOU = []
    GIOU = []
    num = (boxes1[:,0]).size
    x1 = boxes1[:,0]
    y1 = boxes1[:,1]
    x2 = boxes1[:,2]
    y2 = boxes1[:,3]

    xx1=boxes2[:,0]
    yy1=boxes2[:,1]
    xx2=boxes2[:,2]
    yy2=boxes2[:,3]

    area1 = (x2 -x1) * (y2 -y1)  #求取框的面积
    area2 = (xx2-xx1) * (yy2- yy1)
    for i in range (num):
        inter_max_x = np.minimum(x2[i], xx2[:])   #求取重合的坐标及面积
        inter_max_y = np.minimum(y2[i], yy2[:])
        inter_min_x = np.maximum(x1[i], xx1[:])
        inter_min_y = np.maximum(y1[i], yy1[:])
        inter_w = np.maximum(0 ,inter_max_x-inter_min_x)
        inter_h = np.maximum(0 ,inter_max_y-inter_mi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值