# yunet

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

## Classes

| Name | Description |
| --- | --- |
| [`YuNetParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser) | Parser class for parsing the output of the YuNet face detection model. |

### class `YuNetParser`

```python
class YuNetParser(DetectionParser)
```

Parser class for parsing the output of the YuNet face detection model.

> **Note**
> Emits `dai.ImgDetections` messages. dai.ImgDetections message containing bounding boxes, labels, confidence scores, and keypoints of detected faces.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `conf_output_layer_name` |  | Name of the output layer containing the confidence predictions. |
| `conf_threshold` |  | Confidence score threshold for detected faces. |
| `input_shape` |  |  |
| `input_size` |  | Input size (width, height). |
| `iou_output_layer_name` |  | Name of the output layer containing the IoU predictions. |
| `iou_threshold` |  | Non-maximum suppression threshold. |
| `label_names` | `list[str]` |  |
| `layout` |  |  |
| `loc_output_layer_name` |  | Name of the output layer containing the location predictions. |
| `max_det` |  | Maximum number of detections to keep. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-compute) | Compute parser results from extracted tensors without sending messages. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-emit) | Create a `dai.ImgDetections` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-extract) | Select and dequantize the model tensors needed for parsing. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setInputSize`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-setInputSize) | Sets the input size of the model. |
| [`setOutputLayerConf`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-setOutputLayerConf) | Sets the name of the output layer containing the confidence predictions. |
| [`setOutputLayerIou`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-setOutputLayerIou) | Sets the name of the output layer containing the IoU predictions. |
| [`setOutputLayerLoc`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/yunet.md#yunet-Classes-YuNetParser-setOutputLayerLoc) | Sets the name of the output layer containing the location predictions. |

#### method `__init__`

```python
def __init__(
    conf_threshold: float = 0.8,
    iou_threshold: float = 0.3,
    max_det: int = 5000,
    input_size: tuple[int, int] = None,
    loc_output_layer_name: str = None,
    conf_output_layer_name: str = None,
    iou_output_layer_name: str = None,
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `conf_threshold` | `float` | Confidence score threshold for detected faces. | `0.8` |
| `iou_threshold` | `float` | Non-maximum suppression threshold. | `0.3` |
| `max_det` | `int` | Maximum number of detections to keep. | `5000` |
| `input_size` | `tuple[int, int]` | Input size of the model (width, height). | `None` |
| `loc_output_layer_name` | `str` | Output layer name for the location predictions. | `None` |
| `conf_output_layer_name` | `str` | Output layer name for the confidence predictions. | `None` |
| `iou_output_layer_name` | `str` | Output layer name for the IoU predictions. | `None` |

#### method `build`

```python
def build(head_config: dict[str, Any]) -> YuNetParser
```

Configures the parser.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `head_config` | `dict[str, Any]` | The head configuration for the parser. | required |

Returns

| Type | Description |
| --- | --- |
| `YuNetParser` | The parser object with the head configuration set. |

#### static method `compute`

```python
def compute(
    *,
    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]
```

Compute parser results from extracted tensors without sending messages.

> **Note**
> Uses [depthai_nodes.node.parsers.utils.yunet.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); see that helper for tensor layout and validation details.

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. |

#### method `emit`

```python
def emit(
    output: dai.NNData,
    bboxes: np.ndarray,
    keypoints: np.ndarray,
    scores: np.ndarray,
    labels: np.ndarray,
    label_names: list[str] | None,
)
```

Create a `dai.ImgDetections` message and send it on `out`.

Copies source timestamps and sequence number, and carries the source image transformation when present.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |
| `bboxes` | `np.ndarray` | Normalized center-XY/width/height boxes returned by `compute()`. | required |
| `keypoints` | `np.ndarray` | Normalized keypoint coordinates returned by `compute()`. | required |
| `scores` | `np.ndarray` | Confidence scores corresponding to the computed payload. | required |
| `labels` | `np.ndarray` | Integer class IDs corresponding to the boxes. | required |
| `label_names` | `list[str] | None` | Optional class names corresponding to the detections. | required |

#### method `extract`

```python
def extract(output: dai.NNData) -> tuple[np.ndarray, np.ndarray, np.ndarray]
```

Select and dequantize the model tensors needed for parsing.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray, np.ndarray]` | The localization, class-confidence, and IoU tensors, in that order. Missing configured names are inferred from unique `loc`, `conf`, and `iou` prefixes. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If a configured layer is absent or inferred layer prefixes are missing or ambiguous. |

#### method `run`

```python
def run()
```

Read queued network outputs, parse them, and emit results while running.

The pipeline invokes this processing loop. It exits when the input queue closes or the node stops.

#### method `setInputSize`

```python
def setInputSize(input_size: tuple[int, int])
```

Sets the input size of the model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `input_size` | `tuple[int, int]` | Input size of the model (width, height). | required |

#### method `setOutputLayerConf`

```python
def setOutputLayerConf(conf_output_layer_name: str)
```

Sets the name of the output layer containing the confidence predictions.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `conf_output_layer_name` | `str` | Output layer name for the conf tensor. | required |

#### method `setOutputLayerIou`

```python
def setOutputLayerIou(iou_output_layer_name: str)
```

Sets the name of the output layer containing the IoU predictions.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `iou_output_layer_name` | `str` | Output layer name for the IoU tensor. | required |

#### method `setOutputLayerLoc`

```python
def setOutputLayerLoc(loc_output_layer_name: str)
```

Sets the name of the output layer containing the location predictions.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `loc_output_layer_name` | `str` | Output layer name for the loc tensor. | required |
