from iaa_od.models import Result
import matplotlib.pyplot as plt
[docs]
def show_iou_sweep(results: list[Result]) -> None:
"""
Function which plots Alpha values against IoU thresholds from a list of Result objects.
Parameters:
results (list[Result]): The list of Result objects containing Kappa and Alpha values for different IoU thresholds.
"""
iou_thresholds: list[float] = []
alpha_values: list[float] = []
unit_counts: list[int] = []
uses_iom: bool = results[0].iom
for res in results:
iou_thresholds.append(res.iou_thr)
if not res.alpha:
raise ValueError("Alpha value missing in one of the results.")
alpha_values.append(res.alpha)
if not res.units:
raise ValueError("Units missing in one of the results.")
unit_counts.append(len(res.units))
# Plot kappa and alpha values against IoU thresholds
_, ax1 = plt.subplots(figsize=(10, 6))
a_line = ax1.plot(iou_thresholds, alpha_values, marker='o', label='Alpha', color='orange')
ax1.set_xlabel('IoU Threshold')
ax1.set_ylabel('Value')
ax1.set_xticks(iou_thresholds)
ax1.set_ylim(0, 1)
ax2 = ax1.twinx()
u_line = ax2.plot(iou_thresholds, unit_counts, marker='o', label='Unit Count', color='green')
ax2.set_ylabel('Number of Units')
ax2.set_ylim(0, max(unit_counts) + 1)
plt.title('Kappa and Alpha vs IoU Thresholds' + (' (Lenient IoU)' if uses_iom else ' (Strict IoU)'))
lines = a_line + u_line
ax1.legend(lines, [line.get_label() for line in lines], loc='upper left')
ax1.grid(True)
plt.show()