# yolo

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

## 类

### YOLOSubtype

#### 属性

##### DEFAULT

##### GOLD

##### P

##### V10

##### V11

##### V12

##### V26

##### V3

##### V3T

##### V3U

##### V3UT

##### V4

##### V4T

##### V5

##### V5U

##### V6

##### V6R1

##### V6R2

##### V7

##### V8

##### V9

## 函数

### compute_yolo_detections

```python
def compute_yolo_detections(*, subtype: YOLOSubtype, layer_names: list[str], outputs_values: list[np.ndarray], strides: list[int] | None = None, conf_threshold: float, n_classes: int, iou_threshold: float, max_det: int, anchors: np.ndarray | None, n_keypoints: int, label_names: list[str] | None, keypoint_label_names: list[str] | None, keypoint_edges: list[tuple[int, int]] | None, input_shape: tuple[int, int] | None = None, kpts_outputs: list[np.ndarray] | None = None, masks_outputs_values: list[np.ndarray] | None = None, protos_output: np.ndarray | None = None, protos_len: int | None = None, mask_conf: float = 0.5, v26_mask_coeffs: np.ndarray | None = None, v26_protos: np.ndarray | None = None, v26_pose_kpts: np.ndarray | None = None) -> dict[str, np.ndarray | list[str] | int | None]:
```

解码 YOLO 检测、姿态或分割张量。

参数

 * `subtype` (`YOLOSubtype`): 控制张量解码的 YOLO 变体。
 * `layer_names` (`list[str]`): 用于区分检测、姿态和分割模式的输出层名称。
 * `outputs_values` (`list[np.ndarray]`): 按输出头排序的检测张量。
 * `strides` (`list[int] | None`): 输出头步长。如果省略，则使用子类型特定的默认值。
 * `conf_threshold` (`float`): 用于过滤候选的最小检测置信度。
 * `n_classes` (`int`): 检测张量中编码的对象类别数量。
 * `iou_threshold` (`float`): 用于非极大值抑制的交并比阈值。
 * `max_det` (`int`): YOLO26 的最大保留检测数。其他子类型使用 `decode_yolo_output` 中的抑制默认值。
 * `anchors` (`np.ndarray | None`): 用于解码模型预测的预计算锚点坐标。
 * `n_keypoints` (`int`): 每个预测编码的关键点数量。
 * `label_names` (`list[str] | None`): 按预测类别 ID 索引的可选类别名称查找。
 * `keypoint_label_names` (`list[str] | None`): 每个检测中关键点的可选名称。
 * `keypoint_edges` (`list[tuple[int, int]] | None`): 定义骨架边缘的关键点索引的可选对。
 * `input_shape` (`tuple[int, int] | None`): 模型输入图像形状，格式为 `(height, width)`。
 * `kpts_outputs` (`list[np.ndarray] | None`): 非 YOLO26 模型的每个头的姿态张量。
 * `masks_outputs_values` (`list[np.ndarray] | None`): 掩码系数张量，按检测头匹配顺序排列。
 * `protos_output` (`np.ndarray | None`): 批处理原型张量，形状为 `(1, channels, height, width)`。
 * `protos_len` (`int | None`): 每个掩码系数向量使用的原型通道数。
 * `mask_conf` (`float`): 用于二值化掩码 logits 的概率阈值。
 * `v26_mask_coeffs` (`np.ndarray | None`): 与检测查询对齐的 YOLO26 掩码系数。
 * `v26_protos` (`np.ndarray | None`): YOLO26 原型掩码。
 * `v26_pose_kpts` (`np.ndarray | None`): 与检测查询对齐的 YOLO26 姿态坐标和置信度。

返回

 * `dict[str, np.ndarray | list[str] | int | None]`: 包含 `mode`（0 检测，1 姿态，2 分割）、归一化
   `bboxes`、`scores`、`labels`、`label_names`、`keypoints`、`keypoints_scores`、`keypoint_label_names`、`keypoint_edges` 和 `masks`
   的字典。框使用中心 XY/宽度/高度。分割掩码包含 int16 检测索引和 -1 背景；其他模式的掩码返回 `None`。

引发

 * `ValueError`: 如果缺少必需的 YOLO26 输入几何或检测输出，类别/关键点计数与张量形状不符，或者掩码实例计数超过 int16 容量。

### decode_yolo26

```python
def decode_yolo26(raw: np.ndarray, conf_threshold: float, max_det: int, extra_raw: np.ndarray | None = None) -> tuple[np.ndarray, np.ndarray | None]:
```

解码 YOLO26 输出以进行检测、分割或姿态。

YOLO26 端到端输出已解码为 xyxy 像素框，并包含预计算的置信度分数（类别分数上的 ReduceMax）在第 4 列。此路径仅应用置信度阈值和 top-k 过滤。它还可以使用保留的行过滤辅助张量，例如掩码系数或关键点。

参数

 * `raw` (`np.ndarray`): 原始检测张量 (N, A, 5+nc)，其中列为 [x1, y1, x2, y2, conf, cls_0, ..., cls_nc-1]。
 * `conf_threshold` (`float`): 置信度阈值。
 * `max_det` (`int`): 最大检测数量。
 * `extra_raw` (`np.ndarray | None`): 可选的辅助张量 (N, A, M)，例如掩码系数或关键点。如果提供，保留的行将作为第二个元素返回。

返回

 * `tuple[np.ndarray, np.ndarray | None]`: 元组，包含（检测结果 (K, 6)，保留的辅助数据 (K, M) 或 None）。

### decode_yolo_output

```python
def decode_yolo_output(yolo_outputs: list[np.ndarray], strides: list[int], anchors: np.ndarray | None = None, kpts: list[np.ndarray] | None = None, conf_thres: float = 0.5, iou_thres: float = 0.45, num_classes: int = 1, det_mode: bool = False, subtype: YOLOSubtype = YOLOSubtype.DEFAULT, max_nms: int = 3000) -> np.ndarray:
```

解码 YOLO 实例分割或姿态估计模型的输出。

参数

 * `yolo_outputs` (`list[np.ndarray]`): YOLO 输出列表。
 * `strides` (`list[int]`): 步长列表。
 * `anchors` (`np.ndarray | None`): 可选的锚点数组。
 * `kpts` (`list[np.ndarray] | None`): 可选的关键点列表。
 * `conf_thres` (`float`): 置信度阈值。
 * `iou_thres` (`float`): 交并比阈值。
 * `num_classes` (`int`): 类别数量。
 * `det_mode` (`bool`): 仅检测模式。如果为 True，输出将只包含 bbox 检测。
 * `subtype` (`YOLOSubtype`): YOLO 版本。
 * `max_nms` (`int`): NMS 后保留的最大框数。

返回

 * `np.ndarray`: NMS 输出。

### make_grid_numpy

```python
def make_grid_numpy(ny: int, nx: int, na: int) -> np.ndarray:
```

创建形状为 (1, na, ny, nx, 2) 的网格

参数

 * `ny` (`int`): y 坐标的数量。
 * `nx` (`int`): x 坐标的数量。
 * `na` (`int`): 锚点数量。

返回

 * `np.ndarray`: 网格。

### non_max_suppression

```python
def non_max_suppression(prediction: np.ndarray, conf_thres: float = 0.5, iou_thres: float = 0.45, classes: list | None = None, num_classes: int = 1, agnostic: bool = False, multi_label: bool = False, max_det: int = 300, max_time_img: float = 0.05, max_nms: int = 30000, max_wh: int = 7680, kpts_mode: bool = False, det_mode: bool = False) -> list[np.ndarray]:
```

对推理结果执行非极大值抑制 (NMS)。

参数

 * `prediction` (`np.ndarray`): 模型的预测，形状 = (batch_size, boxes, xy+wh+...)
 * `conf_thres` (`float`): 置信度阈值。
 * `iou_thres` (`float`): 交并比阈值。
 * `classes` (`list | None`): 用于按类别过滤。
 * `num_classes` (`int`): 类别数量。
 * `agnostic` (`bool`): 如果为 True，则对所有框一起运行 NMS，而不是按类别运行。
 * `multi_label` (`bool`): 多标签分类。
 * `max_det` (`int`): 限制检测数量。
 * `max_time_img` (`float`): 处理图像的最大时间。
 * `max_nms` (`int`): 最大框数。
 * `max_wh` (`int`): 最大宽度和高度。
 * `kpts_mode` (`bool`): 关键点模式。
 * `det_mode` (`bool`): 仅检测模式。如果为 True，输出将只包含 bbox 检测。

返回

 * `list[np.ndarray]`: 检测数组。如果 det_mode 为 False，检测可能包含 kpts 或分割输出。

### parse_kpts

```python
def parse_kpts(kpts: np.ndarray, n_keypoints: int, img_shape: tuple[int, int]) -> list[tuple[float, float, float]]:
```

解析关键点。

参数

 * `kpts` (`np.ndarray`): 结果关键点。
 * `n_keypoints` (`int`): 关键点数量。
 * `img_shape` (`tuple[int, int]`): 模型输入的图像形状，格式为 (height, width)。

返回

 * `list[tuple[float, float, float]]`: 解析后的关键点。

### parse_yolo_output

```python
def parse_yolo_output(out: np.ndarray, stride: int, num_outputs: int, anchors: np.ndarray | None = None, head_id: int = -1, kpts: np.ndarray | None = None, det_mode: bool = False, subtype: YOLOSubtype = YOLOSubtype.DEFAULT) -> np.ndarray:
```

解析 YOLO 模型的单个通道输出。

参数

 * `out` (`np.ndarray`): 给定通道的 YOLO 模型的单个输出。
 * `stride` (`int`): 步长。
 * `num_outputs` (`int`): 模型的输出数量。
 * `anchors` (`np.ndarray | None`): 给定头的锚点。
 * `head_id` (`int`): 头 ID。
 * `kpts` (`np.ndarray | None`): 给定通道的关键点的单个输出。
 * `det_mode` (`bool`): 仅检测模式。
 * `subtype` (`YOLOSubtype`): YOLO 版本。

返回

 * `np.ndarray`: 解析后的输出。

### resolve_yolo_strides

```python
def resolve_yolo_strides(strides: list[int] | tuple[int, ...] | None, subtype: YOLOSubtype, num_outputs: int) -> list[int]:
```

从元数据或默认回退中解析 YOLO 步长。

参数

 * `strides` (`list[int] | tuple[int, ...] | None`): NNArchive 头元数据中的可选步长。
 * `subtype` (`YOLOSubtype`): YOLO 子类型。
 * `num_outputs` (`int`): YOLO 输出头的数量。

返回

 * `list[int]`: 解析后的 YOLO 步长。

## 属性

### logger
