此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

  • 类
  • YOLOComputeInputs
  • YOLOExtendedParser
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包
最后更新
Python API: depthai_nodes.node.parsers.yolo

类

YOLOComputeInputs

用于 YOLO 解码的不可变配置和张量包。由 YOLOExtendedParser.extract() 创建并由 compute() 消费。字段对应于 depthai_nodes.node.parsers.utils.yolo.compute_yolo_detections 的参数。可选的姿态和掩码字段仅在选定的模型模式下填充。即使数据类字段不能重新分配,数组内容仍然可变。

属性

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

用于解析 YOLO 实例分割和姿态估计模型输出的解析器类。

方法

init
Python
1def __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):
初始化解析器节点。参数
  • conf_threshold (float): 检测的置信度阈值
  • n_classes (int): 模型中的类别数量
  • label_names (list[str] | None): 类别的名称
  • iou_threshold (float): 交并比阈值
  • mask_conf (float): 掩码置信度阈值
  • n_keypoints (int): 模型中的关键点数量
  • max_det (int): 要保留的最大检测数量。
  • anchors (list[list[list[float]]] | None): YOLO 模型的锚点
  • subtype (str): YOLO 模型的版本
  • keypoint_label_names (list[str] | None): 关键点的标签
  • keypoint_edges (list[tuple[int, int]] | None): 关键点的连接对。示例:[(0,1), (1,2), (2,3), (3,0)] 表示关键点 0 连接到关键点 1,关键点 1 连接到关键点 2,依此类推。
build
Python
1def build(head_config: dict[str, Any]):
配置解析器。参数
  • head_config (dict[str, Any]): 解析器的头部配置。
返回
  • YOLOExtendedParser: 设置了头部配置的解析器对象。
compute
Python
1def compute(inputs: YOLOComputeInputs) -> dict[str, Any]:
解码准备好的 YOLO 输入包。参数
  • inputs (YOLOComputeInputs): extract() 返回的张量和配置包。
返回
  • dict[str, Any]: 包含 mode(0 检测,1 姿态,2 分割)、归一化的 bboxes、scores、labels、label_names、keypoints、keypoints_scores、keypoint_label_names、keypoint_edges 和 masks 的字典。框使用中心 XY/宽度/高度。分割掩码包含 int16 检测索引和 -1 背景;其他模式的掩码返回 None。
emit
Python
1def emit(output: dai.NNData, payload: dict[str, Any]):
创建 dai.ImgDetections 消息并将其发送到 out。复制源时间戳和序列号,并在存在时携带源图像转换。参数
  • output (dai.NNData): 携带张量和源时间戳、序列号以及可选图像转换的神经网络输出。
  • payload (dict[str, Any]): compute() 返回的字典,包含模式特定的框、分数、标签、关键点和掩码。
extract
Python
1def extract(output: dai.NNData) -> YOLOComputeInputs:
选择并反量化解析所需的模型张量。参数
  • output (dai.NNData): 携带张量和源时间戳、序列号以及可选图像转换的神经网络输出。
返回
  • YOLOComputeInputs: 一个 YOLOComputeInputs 包,包含反量化张量、解析的图像几何、步幅和当前解析器设置。
引发
  • ValueError: 如果 YOLO26 没有配置的输入形状,或者头部步幅无法解析。
run
Python
1def run(self):
读取排队的网络输出,解析它们,并在运行时发出结果。管道调用此处理循环。当输入队列关闭或节点停止时,它会退出。
setAnchors
Python
1def setAnchors(anchors: list[list[list[float]]]):
设置 YOLO 模型的锚点。参数
  • anchors (list[list[list[float]]]): YOLO 模型的锚点。
setConfidenceThreshold
Python
1def setConfidenceThreshold(threshold: float):
设置检测对象的置信度分数阈值。参数
  • threshold (float): 检测对象的置信度分数阈值。
setIouThreshold
Python
1def setIouThreshold(iou_threshold: float):
设置交并比阈值。参数
  • iou_threshold (float): 交并比阈值。
setKeypointEdges
Python
1def setKeypointEdges(keypoint_edges: list[tuple[int, int]]):
设置关键点的边缘。参数
  • keypoint_edges (list[tuple[int, int]]): 关键点的边缘。
setKeypointLabelNames
Python
1def setKeypointLabelNames(keypoint_label_names: list[str]):
设置关键点的标签名称。参数
  • keypoint_label_names (list[str]): 关键点的标签。
setLabelNames
Python
1def setLabelNames(label_names: list[str]):
设置类别的名称。参数
  • label_names (list[str]): 类别的名称。
setMaskConfidence
Python
1def setMaskConfidence(mask_conf: float):
设置掩码置信度阈值。参数
  • mask_conf (float): 掩码置信度阈值。
setNumClasses
Python
1def setNumClasses(n_classes: int):
设置模型中的类别数量。参数
  • n_classes (int): 模型中的类别数量。
setNumKeypoints
Python
1def setNumKeypoints(n_keypoints: int):
设置模型中的关键点数量。参数
  • n_keypoints (int): 模型中的关键点数量。
setOutputLayerNames
Python
1def setOutputLayerNames(output_layer_names: list[str]):
设置解析器的输出层名称。参数
  • output_layer_names (list[str]): 解析器的输出层名称。
setStrides
Python
1def setStrides(strides: list[int] | tuple[int, ...]):
设置 YOLO 输出头部的步幅。参数
  • strides (list[int] | tuple[int, ...]): YOLO 输出头部的步幅。
setSubtype
Python
1def setSubtype(subtype: str):
设置 YOLO 模型的子类型。参数
  • subtype (str): YOLO 模型的子类型。

属性

anchors
YOLO 模型的锚点(可选)。
conf_threshold
检测对象的置信度分数阈值。
input_shape
iou_threshold
交并比阈值。
keypoint_edges
定义骨架边缘的关键点索引对。例如,[(0, 1), (1, 2)] 将关键点 0 连接到 1,将 1 连接到 2。
keypoint_label_names
关键点的标签。
label_names
类别的名称。
mask_conf
掩码置信度阈值。
max_det
n_classes
模型中的类别数量。
n_keypoints
模型中的关键点数量。
n_prototypes
output_layer_names
strides
YOLO 输出头部的步幅。
subtype
YOLO 模型的版本。