ml.postprocessing.mediapipe --- Google Mediapipe

ml.postprocessing.mediapipe 模块包含用于 Google Mediapipe 模型的后处理器。

class mediapipe_detection_postprocess -- 通用 Mediapipe 检测器

BlazeFaceBlazePalm 共享的基类。解码基于锚框的边界框和关键点,然后执行 NMS。

class ml.postprocessing.mediapipe.mediapipe_detection_postprocess(threshold: float = 0.6, anchors: ndarray | None = None, anchor_grid: list[tuple[int, int]] | None = None, scores: list[int] = [], cords: list[int] = [], nms_threshold: float = 0.1, nms_sigma: float = 0.1)

创建一个通用 Mediapipe 检测后处理器。

threshold 在 sigmoid 之前应用于原始 logits 的分数阈值。

anchors 可选的预构建锚框数组,形状为 (N, 2),包含归一化到 [0, 1](cx, cy) 中心点。若为 None,则从 anchor_grid 生成锚框。

anchor_gridanchorsNone 时用于生成锚框的 (grid_size, scales) 元组列表。

scores 包含分数张量的模型输出索引列表。

cords 包含边界框/关键点张量的模型输出索引列表。

nms_threshold 用于非极大值抑制的 IoU 阈值。

nms_sigma 用于 soft-NMS 分数衰减的 Sigma 值。

__call__(model: ml.Model, inputs: list, outputs: list) list

在模型输出上运行后处理,并返回一个 ((x, y, w, h), score, keypoints) 元组列表。当没有检测结果通过分数阈值时,返回空元组 ()

detection_post_process(ih: int, iw: int, nms: ml.utils.NMS, model: ml.Model, inputs: list, outputs: list, score_idx: int, cords_idx: int, t: float, anchors: ndarray) None

将单个 (score, cords) 输出对中的边界框解码并添加到所提供的 NMS 累加器中。

class BlazeFace -- 人脸检测

对 BlazeFace 模型输出进行后处理。

class ml.postprocessing.mediapipe.BlazeFace(threshold: float = 0.6, anchors: ndarray | None = None, nms_threshold: float = 0.1, nms_sigma: float = 0.1)

创建一个 BlazeFace 后处理器。使用 [(16, 2), (8, 6)] 的锚框网格,分数输出为 [1, 2],边界框输出为 [0, 3]

threshold 用于检测的分数阈值。

anchors 可选的预构建锚框数组;若为 None 则自动生成。

nms_threshold 用于非极大值抑制的 IoU 阈值。

nms_sigma 用于 soft-NMS 分数衰减的 Sigma 值。

__call__ 返回一个 ((x, y, w, h), score, keypoints) 元组列表,其中 keypoints 是一个 (x, y) 点的列表。

class BlazePalm -- 手掌检测

对 BlazePalm 模型输出进行后处理。

class ml.postprocessing.mediapipe.BlazePalm(threshold: float = 0.6, anchors: ndarray | None = None, nms_threshold: float = 0.1, nms_sigma: float = 0.1)

创建一个 BlazePalm 后处理器。使用 [(24, 2), (12, 6)] 的锚框网格,分数输出为 [0],边界框输出为 [1]

threshold 用于检测的分数阈值。

anchors 可选的预构建锚框数组;若为 None 则自动生成。

nms_threshold 用于非极大值抑制的 IoU 阈值。

nms_sigma 用于 soft-NMS 分数衰减的 Sigma 值。

__call__ 返回一个 ((x, y, w, h), score, keypoints) 元组列表,其中 keypoints 是一个 (x, y) 点的列表。

class FaceLandmarks -- 人脸关键点

对 FaceLandmarks 模型输出进行后处理。

class ml.postprocessing.mediapipe.FaceLandmarks(threshold: float = 0.6, nms_threshold: float = 0.1, nms_sigma: float = 0.1)

创建一个 FaceLandmarks 后处理器。

threshold 用于接受一个检测结果的分数阈值(在 sigmoid 之后)。

nms_threshold 用于非极大值抑制的 IoU 阈值。

nms_sigma 用于 soft-NMS 分数衰减的 Sigma 值。

__call__ 返回一个 ((x, y, w, h), score, keypoints) 元组列表,其中 keypoints 是一个 (x, y, z) 点的列表。

class HandLandmarks -- 手部关键点

对 HandLandmarks 模型输出进行后处理。

class ml.postprocessing.mediapipe.HandLandmarks(threshold: float = 0.6, nms_threshold: float = 0.1, nms_sigma: float = 0.1)

创建一个 HandLandmarks 后处理器。

threshold 用于接受一个检测结果的分数阈值。

nms_threshold 用于非极大值抑制的 IoU 阈值。

nms_sigma 用于 soft-NMS 分数衰减的 Sigma 值。

__call__ 返回 [[((x, y, w, h), score, keypoints)]],每个左右手类别(左=0,右=1)对应一个内层列表。keypoints 是一个 (x, y, z) 点的列表。空的类别列表会被保留,以使每个列表的索引与类别索引相匹配。

class MoveNet -- 姿态估计

对 MoveNet 单姿态模型输出进行后处理。

class ml.postprocessing.mediapipe.MoveNet(threshold: float = 0.6, nms_threshold: float = 0.1, nms_sigma: float = 0.1)

创建一个 MoveNet 后处理器。

threshold 逐关键点的置信度阈值;低于此值的关键点会被排除在边界框和平均分数之外。

nms_threshold 用于非极大值抑制的 IoU 阈值。

nms_sigma 用于 soft-NMS 分数衰减的 Sigma 值。

__call__ 返回一个 ((x, y, w, h), score, keypoints) 元组列表,其中 keypoints 是一个以输入像素坐标表示的 (x, y, score) 点的列表。