IOU

IOU
即交并比,应用:NMS(过滤重叠框)mAP

import numpt as np

def get_IOU(pred_bbox, gt_bbox):
	ixmin = max(pred_bbox[0], gt_bbox[0])
	iymin = max(pred_bbox[1], gt_bbox[1])
	ixmax = min(pred_bbox[2], gt_bbox[2])
	iymax = min(pred_bbox[3], gt_bbox[3])
	iw = np.maximum(ixmax - ixmin + 1., 0.)
	ih = np.maximum(iymax - iymin + 1., 0.)

	inters = iw * ih
	uni = ((pred_bbox[2] - pred_bbox[0] + 1.) * (pred_bbox[3] - pred_bbox[1] + 1.) + (gt_bbox[2] - gt_bbox[0] + 1.) * (gt_bbox[3] - gt_bbox[1] + 1.) - inters)

	overlaps = inters / uni
	return overlaps

def get_max_IOU(pred_bboxes, gt_bbox):
	if pred_bboxs.shape[0] > 0:
		ixmin = np.maximum(pred_bboxes[:, 0], gt_bbox[0])
		iymin = np.maximum(pred_bboxes[:, 1], gt_bbox[1])
		ixmax = np.minimum(pred_bboxes[:, 2], gt_bbox[2])
		iymax = np.minimum(pred_bboxes[:, 3], gt_bbox[3])
		iw = np.maximum(ixmax - ixmin + 1., 0.)
		ih = np.maximum(iymax - iymin + 1., 0.)

		inters = iw * ih
		uni = ((gt_bbox[2] - gt_bbox[0] + 1.) * (gt_bbox[3] - gt_bbox[1] + 1.) + (pred_bboxes[:, 2] - pred_bboxes[:, 0] + 1.) * (pred_bboxes[:, 3] - pred_bboxes[:, 1] + 1.) - inters)
		overlaps = inters / uni
		ovmax = np.max(overlaps)
		jmax = np.argmax(overlaps)

	return overlaps, ovmax, jmax

MIoU
IOU_第1张图片
MPA (均精度):计算橙色与红色圆的比例;
MIoU:计算两圆交集(橙色部分)与两圆并集(红橙黄)之间比例,理想状态两圆重合,比例为1.

代码解析:https://blog.csdn.net/jiongnima/article/details/84750819

你可能感兴趣的:(code,图像处理,Python)