mirror of
https://github.com/THU-MIG/yolov10.git
synced 2025-05-23 13:34:23 +08:00

Co-authored-by: Ayush Chaurasia <ayush.chuararsia@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
29 lines
794 B
Python
29 lines
794 B
Python
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
|
|
"""
|
|
Model validation metrics
|
|
"""
|
|
|
|
import numpy as np
|
|
|
|
|
|
def bbox_ioa(box1, box2, eps=1e-7):
|
|
"""Returns the intersection over box2 area given box1, box2. Boxes are x1y1x2y2
|
|
box1: np.array of shape(4)
|
|
box2: np.array of shape(nx4)
|
|
returns: np.array of shape(n)
|
|
"""
|
|
|
|
# Get the coordinates of bounding boxes
|
|
b1_x1, b1_y1, b1_x2, b1_y2 = box1
|
|
b2_x1, b2_y1, b2_x2, b2_y2 = box2.T
|
|
|
|
# Intersection area
|
|
inter_area = (np.minimum(b1_x2, b2_x2) - np.maximum(b1_x1, b2_x1)).clip(0) * \
|
|
(np.minimum(b1_y2, b2_y2) - np.maximum(b1_y1, b2_y1)).clip(0)
|
|
|
|
# box2 area
|
|
box2_area = (b2_x2 - b2_x1) * (b2_y2 - b2_y1) + eps
|
|
|
|
# Intersection over box2 area
|
|
return inter_area / box2_area
|