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

本页目录

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

Classes

RFDETRParser

用于解析 RF-DETR 对象检测模型输出的解析器类。来自 Roboflow 的 RF-DETR 是一种检测 Transformer 模型,可输出边界框和类别概率。该模型可以选择性地输出实例分割掩码。参考:RF-DETR:https://github.com/roboflow/rf-detr

Methods

init
Python
1def __init__(conf_threshold: float = 0.5, max_det: int = 300, label_names: list[str] | None = None, mask_conf: float = 0.5):
初始化解析器节点。Parameters
  • conf_threshold (float): 检测对象的置信度分数阈值。
  • max_det (int): 要保留的最大检测数量。
  • label_names (list[str] | None): 检测对象的标签名称列表。
  • mask_conf (float): 实例分割掩码的掩码置信度阈值。
build
Python
1def build(head_config: dict[str, Any]) -> RFDETRParser:
根据头部配置配置解析器。Parameters
  • head_config (dict[str, Any]): 解析器的头部配置。
Returns
  • RFDETRParser: 设置了头部配置的解析器对象。
compute
Python
1def compute(boxes_tensor: np.ndarray, logits_tensor: np.ndarray, *, conf_threshold: float, max_det: int, label_names: list[str] | None, mask_conf: float, input_shape: tuple[int, int] | None, masks_tensor: np.ndarray | None = None) -> tuple[np.ndarray, np.ndarray, np.ndarray, list[str] | None, np.ndarray | None]:
在不发送消息的情况下,从提取的张量计算解析器结果。Parameters
  • boxes_tensor (np.ndarray): 批处理的归一化中心 XY/宽度/高度预测。
  • logits_tensor (np.ndarray): 形状为 (1, queries, classes) 的类别 logits。
  • conf_threshold (float): 用于过滤候选的最小检测置信度。
  • max_det (int): 在抑制期间保留或考虑的最大检测候选数量。
  • label_names (list[str] | None): 按预测类别 ID 索引的可选类别名称查找。
  • mask_conf (float): 用于二值化掩码 logits 的概率阈值。
  • input_shape (tuple[int, int] | None): 模型输入图像形状,格式为 (height, width)。
  • masks_tensor (np.ndarray | None): 可选的每个查询掩码 logits,按框预测的顺序排列。
Returns
  • tuple[np.ndarray, np.ndarray, np.ndarray, list[str] | None, np.ndarray | None]: 归一化中心 XY/宽度/高度格式的框、分数、整数类别 ID、可选类别名称以及可选的 HW uint8 实例掩码。掩码值索引返回的检测;255 是背景。分割最多保留 255 个实例,置信度更高的掩码会覆盖重叠部分。
emit
Python
1def emit(output: dai.NNData, boxes: np.ndarray, scores: np.ndarray, labels: np.ndarray, label_names_list: list[str] | None, final_mask: np.ndarray | None):
创建 dai.ImgDetections 消息并将其发送到 out。复制源时间戳和序列号,并在存在时携带源图像转换。Parameters
  • output (dai.NNData): 携带张量和源时间戳、序列号以及可选图像转换的神经网络输出。
  • boxes (np.ndarray): compute() 返回的归一化中心 XY/宽度/高度框。
  • scores (np.ndarray): 与计算负载对应的置信度分数。
  • labels (np.ndarray): 与框对应的整数类别 ID。
  • label_names_list (list[str] | None): 与检测对应的可选类别名称。
  • final_mask (np.ndarray | None): 可选的实例掩码,其 ID 索引返回的检测;255 是背景。
extract
Python
1def extract(output: dai.NNData) -> tuple[np.ndarray, np.ndarray, np.ndarray | None]:
选择并反量化解析所需的模型张量。Parameters
  • output (dai.NNData): 携带张量和源时间戳、序列号以及可选图像转换的神经网络输出。
Returns
  • tuple[np.ndarray, np.ndarray, np.ndarray | None]: 浮点 32 框、类别 logits 和可选掩码张量,按配置的层顺序排列。如果没有掩码层,则第三个值为 None。
Raises
  • ValueError: 如果选定的输出不包含两层或三层。
run
Python
1def run(self):
读取排队的网络输出,解析它们,并在运行时发出结果。管道调用此处理循环。当输入队列关闭或节点停止时,它会退出。
setConfidenceThreshold
Python
1def setConfidenceThreshold(threshold: float):
设置检测对象的置信度分数阈值。Parameters
  • threshold (float): 检测对象的置信度分数阈值。
setLabelNames
Python
1def setLabelNames(label_names: list[str]):
设置检测对象的标签名称。Parameters
  • label_names (list[str]): 检测对象的标签名称列表。
setMaskConfidence
Python
1def setMaskConfidence(mask_conf: float):
设置掩码置信度阈值。Parameters
  • mask_conf (float): 掩码置信度阈值。
setMaxDetections
Python
1def setMaxDetections(max_det: int):
设置要保留的最大检测数量。Parameters
  • max_det (int): 要保留的最大检测数量。
setOutputLayerNames
Python
1def setOutputLayerNames(output_layer_names: list[str]):
设置解析器的输出层名称。Parameters
  • output_layer_names (list[str]): 输出层名称列表。

Attributes

conf_threshold
检测对象的置信度分数阈值。
input
接受 dai.NNData 的输入端口。
input_shape
label_names
检测对象的标签名称列表。
mask_conf
用于二值化实例分割掩码的置信度阈值。
max_det
要保留的最大检测数量。
out
携带解析消息的输出端口。
output_layer_names
输出层(框、logits 和可选掩码)的名称。