# yunet

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

## Functions

| Name | Description |
| --- | --- |
| [`compute_yunet_detections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yunet.md#yunet-Functions-compute_yunet_detections) | Decode YuNet tensors, filter scores, and suppress overlapping faces. |
| [`decode_and_prune_detections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yunet.md#yunet-Functions-decode_and_prune_detections) | Optimized function that combines decode_detections and prune_detections. Performs early pruning to avoid processing low-confidence detections. |
| [`decode_detections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yunet.md#yunet-Functions-decode_detections) | 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) |
| [`format_detections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yunet.md#yunet-Functions-format_detections) | Format detections into a list of dictionaries. |
| [`generate_anchors`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yunet.md#yunet-Functions-generate_anchors) | 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) |
| [`manual_product`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yunet.md#yunet-Functions-manual_product) | You can use this function instead of itertools.product. |
| [`prune_detections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yunet.md#yunet-Functions-prune_detections) | Prune detections based on confidence threshold. |

### function `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.

Args

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

Returns

| Type | Description |
| --- | --- |
| `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. |

### function `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.

Args

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

Returns

| Type | Description |
| --- | --- |
|  | A tuple of bboxes, keypoints, and scores. |

### function `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)

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `input_size` | `tuple[int, int]` | The size of the input image (height, width). | required |
| `loc` | `np.ndarray` | The predicted locations (or offsets) of the bounding boxes. | required |
| `conf` | `np.ndarray` | The predicted class confidence scores. | required |
| `iou` | `np.ndarray` | The predicted IoU (Intersection over Union) scores. | required |
| `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. | `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.

### function `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.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bboxes` | `np.ndarray` | A numpy array of shape (N, 4) containing the bounding boxes. | required |
| `keypoints` | `np.ndarray` | A numpy array of shape (N, 10) containing the keypoints. | required |
| `scores` | `np.ndarray` | A numpy array of shape (N,) containing the scores. | required |
| `input_size` | `tuple[int, int]` | A tuple representing the width and height of the input image. | required |

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.

### function `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)

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `input_size` | `tuple[int, int]` | A tuple representing the width and height of the input image. | required |
| `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. | `None` |
| `strides` | `list[int] | None` | Strides for each feature map layer. If None then '[8, 16, 32, 64]' will be used. Defaults to None. | `None` |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Anchors. |

### function `manual_product`

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

You can use this function instead of itertools.product.

### function `prune_detections`

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

Prune detections based on confidence threshold.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bboxes` | `np.ndarray` | A numpy array of shape (N, 4) containing the bounding boxes. | required |
| `keypoints` | `np.ndarray` | A numpy array of shape (N, 10) containing the keypoints. | required |
| `scores` | `np.ndarray` | A numpy array of shape (N,) containing the scores. | required |
| `conf_threshold` | `float` | The confidence threshold. | required |

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.
