# yolo

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

## Classes

### YOLOComputeInputs

Immutable configuration and tensor bundle for YOLO decoding.

Created by `YOLOExtendedParser.extract()` and consumed by `compute()`. Fields correspond to arguments of
[depthai_nodes.node.parsers.utils.yolo.compute_yolo_detections](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yolo.md).
Optional pose and mask fields are populated only for the selected model mode. Array contents remain mutable even though the
dataclass fields cannot be reassigned.

#### Attributes

##### anchors

##### conf_threshold

##### input_shape

##### iou_threshold

##### keypoint_edges

##### keypoint_label_names

##### kpts_outputs

##### label_names

##### layer_names

##### mask_conf

##### masks_outputs_values

##### max_det

##### n_classes

##### n_keypoints

##### outputs_values

##### protos_len

##### protos_output

##### strides

##### subtype

##### v26_mask_coeffs

##### v26_pose_kpts

##### v26_protos

### YOLOExtendedParser

Parser class for parsing the output of the YOLO Instance Segmentation and Pose Estimation models.

> **Note**
> Emits `dai.ImgDetections` messages. dai.ImgDetections message containing bounding boxes, labels, label names, confidence scores, and keypoints or masks and protos of the detected objects.

#### Methods

##### init

```python
def __init__(conf_threshold: float = 0.5, n_classes: int = 1, label_names: list[str] | None = None, iou_threshold: float = 0.5, mask_conf: float = 0.5, n_keypoints: int = 17, max_det: int = 300, anchors: list[list[list[float]]] | None = None, subtype: str = '', keypoint_label_names: list[str] | None = None, keypoint_edges: list[tuple[int, int]] | None = None):
```

Initialize the parser node.

Parameters

 * `conf_threshold` (`float`): The confidence threshold for the detections
 * `n_classes` (`int`): The number of classes in the model
 * `label_names` (`list[str] | None`): The names of the classes
 * `iou_threshold` (`float`): The intersection over union threshold
 * `mask_conf` (`float`): The mask confidence threshold
 * `n_keypoints` (`int`): The number of keypoints in the model
 * `max_det` (`int`): Maximum number of detections to retain.
 * `anchors` (`list[list[list[float]]] | None`): The anchors for the YOLO model
 * `subtype` (`str`): The version of the YOLO model
 * `keypoint_label_names` (`list[str] | None`): The labels for the keypoints
 * `keypoint_edges` (`list[tuple[int, int]] | None`): Connection pairs of the keypoints. Example: [(0,1), (1,2), (2,3), (3,0)]
   shows that keypoint 0 is connected to keypoint 1, keypoint 1 is connected to keypoint 2, etc.

##### build

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

Configures the parser.

Parameters

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

Returns

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

##### compute

```python
def compute(inputs: YOLOComputeInputs) -> dict[str, Any]:
```

Decode a prepared YOLO input bundle.

> **Note**
> Uses [depthai_nodes.node.parsers.utils.yolo.compute_yolo_detections](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/yolo.md) for decoding and validation.

Parameters

 * `inputs` (`YOLOComputeInputs`): Tensor and configuration bundle returned by `extract()`.

Returns

 * `dict[str, Any]`: A dictionary containing `mode` (0 detection, 1 pose, 2 segmentation), normalized `bboxes`, `scores`,
   `labels`, `label_names`, `keypoints`, `keypoints_scores`, `keypoint_label_names`, `keypoint_edges`, and `masks`. Boxes use
   center-XY/width/height. A segmentation mask contains int16 detection indexes and -1 background; other modes return `None` for
   masks.

##### emit

```python
def emit(output: dai.NNData, payload: dict[str, Any]):
```

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.
 * `payload` (`dict[str, Any]`): Dictionary returned by `compute()` with the mode-specific boxes, scores, labels, keypoints, and
   masks.

##### extract

```python
def extract(output: dai.NNData) -> YOLOComputeInputs:
```

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

 * `YOLOComputeInputs`: A `YOLOComputeInputs` bundle with dequantized tensors, resolved image geometry, strides, and current
   parser settings.

Raises

 * `ValueError`: If YOLO26 has no configured input shape, or head strides cannot be resolved.

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

##### setAnchors

```python
def setAnchors(anchors: list[list[list[float]]]):
```

Sets the anchors for the YOLO model.

Parameters

 * `anchors` (`list[list[list[float]]]`): The anchors for the YOLO model.

##### setConfidenceThreshold

```python
def setConfidenceThreshold(threshold: float):
```

Sets the confidence score threshold for detected objects.

Parameters

 * `threshold` (`float`): Confidence score threshold for detected objects.

##### setIouThreshold

```python
def setIouThreshold(iou_threshold: float):
```

Sets the intersection over union threshold.

Parameters

 * `iou_threshold` (`float`): The intersection over union threshold.

##### setKeypointEdges

```python
def setKeypointEdges(keypoint_edges: list[tuple[int, int]]):
```

Sets the edges for the keypoints.

Parameters

 * `keypoint_edges` (`list[tuple[int, int]]`): The edges for the keypoints.

##### setKeypointLabelNames

```python
def setKeypointLabelNames(keypoint_label_names: list[str]):
```

Sets the label names for the keypoints.

Parameters

 * `keypoint_label_names` (`list[str]`): The labels for the keypoints.

##### setLabelNames

```python
def setLabelNames(label_names: list[str]):
```

Sets the names of the classes.

Parameters

 * `label_names` (`list[str]`): The names of the classes.

##### setMaskConfidence

```python
def setMaskConfidence(mask_conf: float):
```

Sets the mask confidence threshold.

Parameters

 * `mask_conf` (`float`): The mask confidence threshold.

##### setNumClasses

```python
def setNumClasses(n_classes: int):
```

Sets the number of classes in the model.

Parameters

 * `n_classes` (`int`): The number of classes in the model.

##### setNumKeypoints

```python
def setNumKeypoints(n_keypoints: int):
```

Sets the number of keypoints in the model.

Parameters

 * `n_keypoints` (`int`): The number of keypoints in the model.

##### setOutputLayerNames

```python
def setOutputLayerNames(output_layer_names: list[str]):
```

Sets the output layer names for the parser.

Parameters

 * `output_layer_names` (`list[str]`): The output layer names for the parser.

##### setStrides

```python
def setStrides(strides: list[int] | tuple[int, ...]):
```

Sets the strides for YOLO output heads.

Parameters

 * `strides` (`list[int] | tuple[int, ...]`): Strides for YOLO output heads.

##### setSubtype

```python
def setSubtype(subtype: str):
```

Sets the subtype of the YOLO model.

Parameters

 * `subtype` (`str`): The subtype of the YOLO model.

#### Attributes

##### anchors

Anchors for the YOLO model (optional).

##### conf_threshold

Confidence score threshold for detected objects.

##### input_shape

##### iou_threshold

Intersection over union threshold.

##### keypoint_edges

Pairs of keypoint indexes defining skeleton edges. For example, `[(0, 1), (1, 2)]` connects keypoint 0 to 1 and 1 to 2.

##### keypoint_label_names

Labels for the keypoints.

##### label_names

Names of the classes.

##### mask_conf

Mask confidence threshold.

##### max_det

##### n_classes

Number of classes in the model.

##### n_keypoints

Number of keypoints in the model.

##### n_prototypes

##### output_layer_names

##### strides

Strides for the YOLO output heads.

##### subtype

Version of the YOLO model.
