from iaa_od.metrics.alpha import alpha
from iaa_od.models import GroundTruthProtocol, Result
from typing import Optional
[docs]
def iou_sweep(gts: list[GroundTruthProtocol], start: Optional[float] = None, stop: Optional[float] = None, step: Optional[float] = None, /, *, use_iom: bool = False) -> list[Result]:
"""
Compute Kappa and Alpha metrics for different IoU thresholds in the specified range.
Parameters:
gts (list[GroundTruthProtocol]): List of Ground Truths to compare.
start (Optional[float]): Starting IoU threshold (inclusive). Defaults to 0.5 if None.
stop (Optional[float]): Ending IoU threshold (inclusive). Defaults to 0.95 if None.
step (Optional[float]): Step size for IoU thresholds. Defaults to 0.05 if None.
use_iom (bool): Whether to use IoM matching. Defaults to False.
Returns:
list[Result]: List of Result objects corresponding to each IoU threshold.
"""
# Check that the list of GroundTruths has at least two elements
if not gts or len(gts) < 2:
raise ValueError("At least two GroundTruth objects are required for agreement computation.")
# Default to standard IoU sweep values if parameters are None
if not start:
start = 0.5
if not stop:
stop = 0.95
if not step:
step = 0.05
# Initialise empty lists
results: list[Result] = []
thresholds: list[float] = []
# Generate IoU thresholds
t: float = start
while t <= stop + step:
thresholds.append(round(t, 10))
t += step
# Compute Kappa and Alpha for each threshold
for threshold in thresholds:
result: Result = alpha(
gts,
iou_threshold=threshold,
use_iom=use_iom,
)
results.append(result)
# Return results
return results