yolo
最后更新
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
1def 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]: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
1def decode_yolo26(raw: np.ndarray, conf_threshold: float, max_det: int, extra_raw: np.ndarray | None = None) -> tuple[np.ndarray, np.ndarray | None]: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
1def 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_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
1def make_grid_numpy(ny: int, nx: int, na: int) -> np.ndarray:ny(int): y 坐标的数量。nx(int): x 坐标的数量。na(int): 锚点数量。
np.ndarray: 网格。
non_max_suppression
Python
1def 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]: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
1def 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
1def 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: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
1def resolve_yolo_strides(strides: list[int] | tuple[int, ...] | None, subtype: YOLOSubtype, num_outputs: int) -> list[int]:strides(list[int] | tuple[int, ...] | None): NNArchive 头元数据中的可选步长。subtype(YOLOSubtype): YOLO 子类型。num_outputs(int): YOLO 输出头的数量。
list[int]: 解析后的 YOLO 步长。