# yunet

Python API: `depthai_nodes.node.parsers.utils.yunet`

## Functions

### compute_yunet_detections

```python
def compute_yunet_detections(*, input_size: tuple[int, int], loc: np.ndarray, conf: np.ndarray, iou: np.ndarray, conf_threshold: float, iou_threshold: float, max_det: int, anchors: np.ndarray, label_names: list[str] | None = None, nms_fn: Callable[..., np.ndarray], top_left_wh_to_xywh_fn: Callable[[np.ndarray], np.ndarray]) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]:
```

Decode YuNet tensors, filter scores, and suppress overlapping faces.

Parameters

 * `input_size` (`tuple[int, int]`): Model input size as `(width, height)`.
 * `loc` (`np.ndarray`): Per-anchor box and five-landmark offsets.
 * `conf` (`np.ndarray`): Per-anchor class-confidence tensor.
 * `iou` (`np.ndarray`): Per-anchor IoU confidence tensor.
 * `conf_threshold` (`float`): Minimum detection confidence used to filter candidates.
 * `iou_threshold` (`float`): Intersection-over-union threshold for non-maximum suppression.
 * `max_det` (`int`): Maximum number of detection candidates to retain or consider during suppression.
 * `anchors` (`np.ndarray`): Precomputed anchor coordinates used to decode model predictions.
 * `label_names` (`list[str] | None`): Optional class-name lookup indexed by predicted class ID.
 * `nms_fn` (`Callable[..., np.ndarray]`): Suppression callable accepting boxes, scores, confidence/IoU thresholds, and `max_det`;
   returns retained indexes.
 * `top_left_wh_to_xywh_fn` (`Callable[[np.ndarray], np.ndarray]`): Callable converting top-left XY/width/height boxes to
   center-XY/width/height.

Returns

 * `tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]`: Normalized center-XY/width/height boxes, five
   normalized XY landmarks per face, scores, zero-valued class IDs, and optional class names. No candidates produces empty arrays.

### decode_and_prune_detections

```python
def decode_and_prune_detections(input_size: tuple[int, int], loc: np.ndarray, conf: np.ndarray, iou: np.ndarray, conf_threshold: float, anchors: np.ndarray, variance: list[float] | None = None):
```

Optimized function that combines decode_detections and prune_detections. Performs early pruning to avoid processing low-confidence
detections.

Parameters

 * `input_size` (`tuple[int, int]`): The size of the input image (width, height).
 * `loc` (`np.ndarray`): The predicted locations (or offsets) of the bounding boxes.
 * `conf` (`np.ndarray`): The predicted class confidence scores.
 * `iou` (`np.ndarray`): The predicted IoU (Intersection over Union) scores.
 * `conf_threshold` (`float`): The confidence threshold for pruning.
 * `anchors` (`np.ndarray`): Pre-computed anchors to avoid regeneration.
 * `variance` (`list[float] | None`): A list of variances used to decode the bounding box predictions.

Returns

 * A tuple of bboxes, keypoints, and scores.

### decode_detections

```python
def decode_detections(input_size: tuple[int, int], loc: np.ndarray, conf: np.ndarray, iou: np.ndarray, variance: list[float] | None = None):
```

Decodes the output of an object detection model by converting the model's predictions (localization, confidence, and IoU scores)
into bounding boxes, keypoints, and scores. The code is taken from
[https://github.com/Kazuhito00/YuNet-ONNX-TFLite-Sample/tree/main](https://github.com/Kazuhito00/YuNet-ONNX-TFLite-Sample/tree/main)

Parameters

 * `input_size` (`tuple[int, int]`): The size of the input image (height, width).
 * `loc` (`np.ndarray`): The predicted locations (or offsets) of the bounding boxes.
 * `conf` (`np.ndarray`): The predicted class confidence scores.
 * `iou` (`np.ndarray`): The predicted IoU (Intersection over Union) scores.
 * `variance` (`list[float] | None`): A list of variances used to decode the bounding box predictions. If None then [0.1,0.2] will
   be used. Defaults to None.

Returns

 * `tuple[np.ndarray, np.ndarray, np.ndarray]`: * `A tuple of bboxes, keypoints, and`: scores: * bboxes: NumPy array of shape (N,
   4) containing the decoded bounding boxes in the format [x_min, y_min, width, height].
       * keypoints: A NumPy array of shape (N, 10) containing the decoded keypoint coordinates for each anchor.
       * scores: A NumPy array of shape (N, 1) containing the combined scores for each anchor.

### format_detections

```python
def format_detections(bboxes: np.ndarray, keypoints: np.ndarray, scores: np.ndarray, input_size: tuple[int, int]):
```

Format detections into a list of dictionaries.

Parameters

 * `bboxes` (`np.ndarray`): A numpy array of shape (N, 4) containing the bounding boxes.
 * `keypoints` (`np.ndarray`): A numpy array of shape (N, 10) containing the keypoints.
 * `scores` (`np.ndarray`): A numpy array of shape (N,) containing the scores.
 * `input_size` (`tuple[int, int]`): A tuple representing the width and height of the input image.

Returns

 * `tuple[np.ndarray, np.ndarray, np.ndarray]`: * `A tuple of bboxes, keypoints, and`: scores: * bboxes: NumPy array of shape (N,
   4) containing the decoded bounding boxes in the format [x_min, y_min, width, height].
       * keypoints: A NumPy array of shape (N, 10) containing the decoded keypoint coordinates for each anchor.
       * scores: A NumPy array of shape (N, 1) containing the combined scores for each anchor.

### generate_anchors

```python
def generate_anchors(input_size: tuple[int, int], min_sizes: list[list[int]] | None = None, strides: list[int] | None = None):
```

Generate a set of default bounding boxes, known as anchors. The code is taken from
[https://github.com/Kazuhito00/YuNet-ONNX-TFLite-Sample/tree/main](https://github.com/Kazuhito00/YuNet-ONNX-TFLite-Sample/tree/main)

Parameters

 * `input_size` (`tuple[int, int]`): A tuple representing the width and height of the input image.
 * `min_sizes` (`list[list[int]] | None`): A list of lists, where each inner list contains the minimum sizes of the anchors for
   different feature maps. If None then '[[10, 16, 24], [32, 48], [64, 96], [128, 192, 256]]' will be used. Defaults to None.
 * `strides` (`list[int] | None`): Strides for each feature map layer. If None then '[8, 16, 32, 64]' will be used. Defaults to
   None.

Returns

 * `np.ndarray`: Anchors.

### manual_product

```python
def manual_product(*args):
```

You can use this function instead of itertools.product.

### prune_detections

```python
def prune_detections(bboxes: np.ndarray, keypoints: np.ndarray, scores: np.ndarray, conf_threshold: float):
```

Prune detections based on confidence threshold.

Parameters

 * `bboxes` (`np.ndarray`): A numpy array of shape (N, 4) containing the bounding boxes.
 * `keypoints` (`np.ndarray`): A numpy array of shape (N, 10) containing the keypoints.
 * `scores` (`np.ndarray`): A numpy array of shape (N,) containing the scores.
 * `conf_threshold` (`float`): The confidence threshold.

Returns

 * `tuple[np.ndarray, np.ndarray, np.ndarray]`: * `A tuple of bboxes, keypoints, and`: scores: * bboxes: NumPy array of shape (N,
   4) containing the decoded bounding boxes in the format [x_min, y_min, width, height].
       * keypoints: A NumPy array of shape (N, 10) containing the decoded keypoint coordinates for each anchor.
       * scores: A NumPy array of shape (N, 1) containing the combined scores for each anchor.
