# yunet

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

## Classes

### YuNetParser

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.

#### Methods

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

Parameters

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

##### build

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

Configures the parser.

Parameters

 * `head_config` (`dict[str, Any]`): The head configuration for the parser.

Returns

 * `YuNetParser`: The parser object with the head configuration set.

##### 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); see that helper for tensor layout and validation details.

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.

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

Parameters

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

##### extract

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

Select and dequantize the model tensors needed for parsing.

Parameters

 * `output` (`dai.NNData`): Neural network output carrying tensors and source timestamps, sequence number, and optional image
   transformation.

Returns

 * `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

 * `ValueError`: If a configured layer is absent or inferred layer prefixes are missing or ambiguous.

##### run

```python
def run(self):
```

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.

##### setInputSize

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

Sets the input size of the model.

Parameters

 * `input_size` (`tuple[int, int]`): Input size of the model (width, height).

##### setOutputLayerConf

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

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

Parameters

 * `conf_output_layer_name` (`str`): Output layer name for the conf tensor.

##### setOutputLayerIou

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

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

Parameters

 * `iou_output_layer_name` (`str`): Output layer name for the IoU tensor.

##### setOutputLayerLoc

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

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

Parameters

 * `loc_output_layer_name` (`str`): Output layer name for the loc tensor.

#### Attributes

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

##### layout

##### loc_output_layer_name

Name of the output layer containing the location predictions.

##### max_det

Maximum number of detections to keep.
