hoops_ai.insights.utils.group_predictions_by_label

hoops_ai.insights.utils.group_predictions_by_label(predictions, palette, exclude_labels=None)

Group face/element indices by their prediction label and attach colors.

Takes an array of predictions (one per face/element) and groups the indices by their predicted label, attaching the corresponding color and description from the palette.

Parameters:
  • predictions (numpy.ndarray) – Array where predictions[i] = label for element i

  • palette (ColorPalette) – ColorPalette with colors and descriptions for each label

  • exclude_labels (Set[int] | None) – Optional set of labels to skip (e.g., {0} for background)

Returns:

List of (indices, color, description) tuples, one per unique label

Return type:

List[Tuple[List[int], Tuple[int, int, int], str]]

Examples

>>> predictions = np.array([0, 17, 17, 23, 0, 23, 17])
>>> # After creating palette...
>>> groups = group_predictions_by_label(predictions, palette, exclude_labels={0})
>>> groups
[
    ([1, 2, 6], (255, 0, 0), 'through hole'),
    ([3, 5], (0, 0, 255), 'blind hole')
]