Source code for iaa_od.metrics.rater_vitality

from iaa_od.metrics import alpha
from iaa_od.models import GroundTruthProtocol, Result, STD_IOU_THR
from typing import Optional

[docs] def all_raters_vitality(gts: list[GroundTruthProtocol], /, *, iou_threshold: float = STD_IOU_THR, use_iom: bool = False, precomputed_result: Optional[Result] = None) -> dict[str, float]: """ Compute the vitality for all raters in the provided Ground Truths. Parameters: gts (list[GroundTruthProtocol]): A list of GroundTruth objects representing the annotations. iou_threshold (float): The IoU threshold to use for matching. Defaults to STD_IOU_THR. use_iom (bool): Whether to use IoM matching. Defaults to False. precomputed_result (Optional[Result]): An optional precomputed Result object containing the overall alpha value. Returns: dict[str, float]: A dictionary mapping each rater's name to their vitality score. """ rater_vitalities = {} # Initialise a set with all rater names rater_names = set(gt.name for gt in gts) # Compute vitality for each rater for rater in rater_names: vitality = rater_vitality(gts, annotator_name=rater, iou_threshold=iou_threshold, use_iom=use_iom, precomputed_result=precomputed_result ) rater_vitalities[rater] = vitality return rater_vitalities
[docs] def rater_vitality(gts: list[GroundTruthProtocol], /, *, annotator_name: str, iou_threshold: float = STD_IOU_THR, use_iom: bool = False, precomputed_result: Optional[Result] = None) -> float: """ Compute the vitality of a specific rater (annotator) in the provided Ground Truths. Parameters: gts (list[GroundTruthProtocol]): A list of GroundTruth objects representing the annotations. annotator_name (Optional[str]): The name of the annotator whose vitality is to be computed. iou_threshold (float): The IoU threshold to use for matching. Defaults to STD_IOU_THR. use_iom (bool): Whether to use IoM matching. Defaults to False. precomputed_result (Optional[Result]): An optional precomputed Result object containing the overall alpha value. Returns: float: The vitality score of the specified rater. """ # Check that either iou_threshold or use_iom are default or precomputed_result is provided if precomputed_result and (iou_threshold != STD_IOU_THR or use_iom): raise ValueError("You cannot provide IoU settings when using a precomputed result.") # Initialise the filtered ground truth list excluding the specified annotator relevant_gts: list[GroundTruthProtocol] = [gt for gt in gts if gt.name != annotator_name] # Ensure there are enough ground truths to compute alpha if len(relevant_gts) < 2: raise ValueError("Not enough ground truths available after excluding the specified annotator or file.") alpha_all: float iou_thr: float iom: bool # If a precomputed result is provided, use its alpha value if precomputed_result and precomputed_result.alpha: alpha_all = precomputed_result.alpha iou_thr = precomputed_result.iou_thr iom = precomputed_result.iom # Otherwise, compute alpha for all ground truths else: result_all: Result = alpha(gts, iou_threshold=iou_threshold, use_iom=use_iom) if result_all.alpha is None: raise ValueError("Something very wrong has happened. Check the alpha computation.") alpha_all = result_all.alpha iou_thr = iou_threshold iom = use_iom # Compute alpha for the relevant ground truths (excluding the specified annotator or file) result_excluded: Result = alpha(relevant_gts, iou_threshold=iou_thr, use_iom=iom ) if result_excluded.alpha is None: raise ValueError("Something very wrong has happened. Check the alpha computation.") alpha_excluded: float = result_excluded.alpha # Compute vitality as the difference in alpha values vitality: float = alpha_all - alpha_excluded return vitality