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

本页目录

  • 函数
  • compute_yunet_detections
  • decode_and_prune_detections
  • decode_detections
  • format_detections
  • generate_anchors
  • manual_product
  • prune_detections
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包
最后更新
Python API: depthai_nodes.node.parsers.utils.yunet

函数

compute_yunet_detections

Python
1def compute_yunet_detections(*, input_size: tuple[int, int], loc: np.ndarray, conf: np.ndarray, iou: np.ndarray, conf_threshold: float, iou_threshold: float, max_det: int, anchors: np.ndarray, label_names: list[str] | None = None, nms_fn: Callable[..., np.ndarray], top_left_wh_to_xywh_fn: Callable[[np.ndarray], np.ndarray]) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]:
解码 YuNet 张量,过滤分数,并抑制重叠人脸。参数
  • input_size (tuple[int, int]): 模型输入大小,格式为 (宽度, 高度)。
  • loc (np.ndarray): 每个锚框和五个关键点的偏移量。
  • conf (np.ndarray): 每个锚框的类别置信度张量。
  • iou (np.ndarray): 每个锚框的 IoU 置信度张量。
  • conf_threshold (float): 用于过滤候选的最小检测置信度。
  • iou_threshold (float): 非极大值抑制的交并比阈值。
  • max_det (int): 在抑制过程中保留或考虑的最大检测候选数量。
  • anchors (np.ndarray): 用于解码模型预测的预计算锚点坐标。
  • label_names (list[str] | None): 可选的类别名称查找,按预测类别 ID 索引。
  • nms_fn (Callable[..., np.ndarray]): 抑制可调用对象,接受框、分数、置信度/IoU 阈值和 max_det;返回保留的索引。
  • top_left_wh_to_xywh_fn (Callable[[np.ndarray], np.ndarray]): 将左上角 XY/宽度/高度框转换为中心 XY/宽度/高度的可调用对象。
返回
  • tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]: 归一化的中心 XY/宽度/高度框,每张人脸的五个归一化 XY 关键点,分数,零值类别 ID,以及可选的类别名称。没有候选时返回空数组。

decode_and_prune_detections

Python
1def decode_and_prune_detections(input_size: tuple[int, int], loc: np.ndarray, conf: np.ndarray, iou: np.ndarray, conf_threshold: float, anchors: np.ndarray, variance: list[float] | None = None):
优化函数,结合了 decode_detections 和 prune_detections。执行早期剪枝以避免处理低置信度检测。参数
  • input_size (tuple[int, int]): 输入图像的大小 (宽度, 高度)。
  • loc (np.ndarray): 边界框的预测位置(或偏移量)。
  • conf (np.ndarray): 预测的类别置信度分数。
  • iou (np.ndarray): 预测的 IoU (交并比) 分数。
  • conf_threshold (float): 用于剪枝的置信度阈值。
  • anchors (np.ndarray): 预计算的锚点,以避免重新生成。
  • variance (list[float] | None): 用于解码边界框预测的方差列表。
返回
  • 包含 bboxes、keypoints 和 scores 的元组。

decode_detections

Python
1def decode_detections(input_size: tuple[int, int], loc: np.ndarray, conf: np.ndarray, iou: np.ndarray, variance: list[float] | None = None):
通过将模型的预测(定位、置信度和 IoU 分数)转换为边界框、关键点和分数来解码对象检测模型的输出。代码取自 https://github.com/Kazuhito00/YuNet-ONNX-TFLite-Sample/tree/main参数
  • input_size (tuple[int, int]): 输入图像的大小 (高度, 宽度)。
  • loc (np.ndarray): 边界框的预测位置(或偏移量)。
  • conf (np.ndarray): 预测的类别置信度分数。
  • iou (np.ndarray): 预测的 IoU (交并比) 分数。
  • variance (list[float] | None): 用于解码边界框预测的方差列表。如果为 None,则使用 [0.1, 0.2]。默认为 None。
返回
  • tuple[np.ndarray, np.ndarray, np.ndarray]:
    • 包含 bboxes、keypoints 和: scores:
      • bboxes: 形状为 (N, 4) 的 NumPy 数组,包含格式为 [x_min, y_min, width, height] 的解码边界框。
      • keypoints: 形状为 (N, 10) 的 NumPy 数组,包含每个锚点的解码关键点坐标。
      • scores: 形状为 (N, 1) 的 NumPy 数组,包含每个锚点的组合分数。

format_detections

Python
1def format_detections(bboxes: np.ndarray, keypoints: np.ndarray, scores: np.ndarray, input_size: tuple[int, int]):
将检测结果格式化为字典列表。参数
  • bboxes (np.ndarray): 形状为 (N, 4) 的 NumPy 数组,包含边界框。
  • keypoints (np.ndarray): 形状为 (N, 10) 的 NumPy 数组,包含关键点。
  • scores (np.ndarray): 形状为 (N,) 的 NumPy 数组,包含分数。
  • input_size (tuple[int, int]): 表示输入图像宽度和高度的元组。
返回
  • tuple[np.ndarray, np.ndarray, np.ndarray]:
    • 包含 bboxes、keypoints 和: scores:
      • bboxes: 形状为 (N, 4) 的 NumPy 数组,包含格式为 [x_min, y_min, width, height] 的解码边界框。
      • keypoints: 形状为 (N, 10) 的 NumPy 数组,包含每个锚点的解码关键点坐标。
      • scores: 形状为 (N, 1) 的 NumPy 数组,包含每个锚点的组合分数。

generate_anchors

Python
1def generate_anchors(input_size: tuple[int, int], min_sizes: list[list[int]] | None = None, strides: list[int] | None = None):
生成一组默认边界框,称为锚点。代码取自 https://github.com/Kazuhito00/YuNet-ONNX-TFLite-Sample/tree/main参数
  • input_size (tuple[int, int]): 表示输入图像宽度和高度的元组。
  • min_sizes (list[list[int]] | None): 列表的列表,其中每个内部列表包含不同特征图的锚点的最小尺寸。如果为 None,则使用 '[[10, 16, 24], [32, 48], [64, 96], [128, 192, 256]]'。默认为 None。
  • strides (list[int] | None): 每个特征图层的步幅。如果为 None,则使用 '[8, 16, 32, 64]'。默认为 None。
返回
  • np.ndarray: 锚点。

manual_product

Python
1def manual_product(*args):
您可以使用此函数代替 itertools.product。

prune_detections

Python
1def prune_detections(bboxes: np.ndarray, keypoints: np.ndarray, scores: np.ndarray, conf_threshold: float):
根据置信度阈值剪枝检测结果。参数
  • bboxes (np.ndarray): 形状为 (N, 4) 的 NumPy 数组,包含边界框。
  • keypoints (np.ndarray): 形状为 (N, 10) 的 NumPy 数组,包含关键点。
  • scores (np.ndarray): 形状为 (N,) 的 NumPy 数组,包含分数。
  • conf_threshold (float): 置信度阈值。
返回
  • tuple[np.ndarray, np.ndarray, np.ndarray]:
    • 包含 bboxes、keypoints 和: scores:
      • bboxes: 形状为 (N, 4) 的 NumPy 数组,包含格式为 [x_min, y_min, width, height] 的解码边界框。
      • keypoints: 形状为 (N, 10) 的 NumPy 数组,包含每个锚点的解码关键点坐标。
      • scores: 形状为 (N, 1) 的 NumPy 数组,包含每个锚点的组合分数。