Utils
- deel.puncc.api.utils.alpha_calib_check(alpha, n, complement_check=False)
Check if the value of alpha
is consistent with the size of calibration set .The quantile order is inflated by a factor
and has to be in the interval (0,1). From this, we derive the condition:If complement_check is set, we consider an additional condition:
- Parameters:
alpha (float or np.ndarray) – target quantile order.
n (int) – size of the calibration dataset.
complement_check (bool) – complementary check to compute the
-th quantile, required by some methods such as jk+.
- Raises:
ValueError – when
is inconsistent with the size of calibration set.
- deel.puncc.api.utils.quantile(a, q, w=None, axis=None, feature_axis=None)
Estimate the columnwise q-th empirical weighted quantiles.
- Parameters:
a (Iterable) – collection of n samples
q (Union[float, np.ndarray]) – q-th quantiles to compute. All elements must be in (0, 1).
w (ndarray) – vector of size n. By default, w is None and equal weights (
) are associated.axis (int) – axis along which to compute quantiles. If None, quantiles are computed along the flattened array.
feature_axis (int) – if multidim quantile, feature_axis is the axis corresponding to the features.
- Raises:
ValueError – all coordinates of q must be in (0, 1).
- Returns:
weighted empirical quantiles.
- Return type:
Union[float, np.ndarray]
- deel.puncc.api.utils.hungarian_assignment(predicted_bboxes, true_bboxes, min_iou=0.5)
Assign predicted bounding boxes to labeled ones based on maximizing IOU. This function relies on the Hungarian algorithm (also known as the Kuhn-Munkres algorithm) to perform the assignment.
- Parameters:
predicted_bboxes (np.ndarray) – Array of predicted bounding boxes with shape (N, 4), where N is the number of predictions.
true_bboxes (np.ndarray) – Array of true bounding boxes with shape (M, 4), where M is the number of true classes.
min_iou (float) – Minimum IoU threshold to consider a prediction as valid, by default 0.5.
- Returns:
A tuple containing 1) an array of aligned predicted bounding boxes that have IoU greater than the minimum threshold and 2) an array of true bounding boxes that correspond to the valid predicted bounding boxes.
- Return type:
tuple[np.ndarray, np.ndarray]
Note
This function pads the predicted bounding boxes to match the number of true bounding boxes if necessary. It then calculates the IoU matrix between true and predicted bounding boxes and performs linear sum assignment to maximize the total IoU. Finally, it filters out the bounding boxes that do not meet the minimum IoU threshold.
Examples
>>> import numpy as np >>> predicted_bboxes = np.array([[10, 10, 50, 50], [20, 20, 60, 60]]) >>> true_bboxes = np.array([[12, 12, 48, 48], [22, 22, 58, 58], [30, 30, 70, 70]]) >>> hungarian_assignment(predicted_bboxes, true_bboxes, min_iou=0.5) (array([[10, 10, 50, 50], [20, 20, 60, 60]]), array([[12, 12, 48, 48], [22, 22, 58, 58]]))