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

本页目录

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

类

FastSAMParser

用于解析 FastSAM 模型输出的解析器类。

方法

init
Python
1def __init__(conf_threshold: float = 0.5, n_classes: int = 1, iou_threshold: float = 0.5, mask_conf: float = 0.5, prompt: str = 'everything', points: tuple[int, int] | None = None, point_label: int | None = None, bbox: tuple[int, int, int, int] | None = None, yolo_outputs: list[str] = None, mask_outputs: list[str] = None, protos_output: str = 'protos_output'):
初始化解析器节点。参数
  • conf_threshold (float): 检测的置信度阈值
  • n_classes (int): 模型中的类别数量
  • iou_threshold (float): 交并比阈值
  • mask_conf (float): 掩码置信度阈值
  • prompt (str): 提示类型
  • points (tuple[int, int] | None): 点
  • point_label (int | None): 点标签
  • bbox (tuple[int, int, int, int] | None): 边界框
  • yolo_outputs (list[str]): YOLO 输出
  • mask_outputs (list[str]): 掩码输出
  • protos_output (str): 原型输出
build
Python
1def build(head_config: dict[str, Any]) -> FastSAMParser:
配置解析器。参数
  • head_config (dict[str, Any]): 解析器的头部配置。
返回
  • FastSAMParser: 设置了头部配置的解析器对象。
compute
Python
1def compute(outputs_values: list[np.ndarray], masks_outputs_values: list[np.ndarray], protos_output: np.ndarray, protos_len: int, *, conf_threshold: float, n_classes: int, iou_threshold: float, mask_conf: float, prompt: str, points: tuple[int, int] | None, point_label: int | None, bbox: tuple[int, int, int, int] | None) -> tuple[np.ndarray, int]:
在不发送消息的情况下,从提取的张量计算解析器结果。参数
  • outputs_values (list[np.ndarray]): 按输出头排序的检测张量。
  • masks_outputs_values (list[np.ndarray]): 按与检测头匹配的顺序排列的掩码系数张量。
  • protos_output (np.ndarray): 批处理的原型张量,形状为 (1, channels, height, width)。
  • protos_len (int): 每个掩码系数向量使用的原型通道数。
  • conf_threshold (float): 用于过滤候选对象的最小检测置信度。
  • n_classes (int): 检测张量中编码的对象类别数。
  • iou_threshold (float): 用于非极大值抑制的交并比阈值。
  • mask_conf (float): 用于二值化掩码 logits 的概率阈值。
  • prompt (str): 掩码选择模式:"everything"、"bbox" 或 "point"。
  • points (tuple[int, int] | None): 用于点选择的图像像素坐标中的提示点。
  • point_label (int | None): 用于包含或排除匹配掩码的点提示标签。
  • bbox (tuple[int, int, int, int] | None): 图像像素坐标中的边界框提示。
返回
  • tuple[np.ndarray, int]: 合并的实例掩码和选定掩码数量的对。未选定掩码会生成一个值为 -1 且计数为 0 的背景掩码。
emit
Python
1def emit(output: dai.NNData, results_masks: np.ndarray, mask_count: int):
创建 dai.SegmentationMask 消息并将其发送到 out。复制源时间戳和序列号,并在存在时携带源图像变换。参数
  • output (dai.NNData): 携带张量和源时间戳、序列号以及可选图像变换的神经网络输出。
  • results_masks (np.ndarray): compute() 返回的合并实例掩码。
  • mask_count (int): 选定掩码的数量,用于日志记录。
extract
Python
1def extract(output: dai.NNData) -> tuple[list[np.ndarray], list[np.ndarray], np.ndarray, int]:
选择并解量化解析所需的模型张量。参数
  • output (dai.NNData): 携带张量和源时间戳、序列号以及可选图像变换的神经网络输出。
返回
  • tuple[list[np.ndarray], list[np.ndarray], np.ndarray, int]: 按词法层名称顺序排列的检测头、掩码系数头、原型张量和原型通道计数;数组是 NCHW 顺序的解量化 float32。
run
Python
1def run(self):
读取排队的网络输出,解析它们,并在运行时发出结果。管道调用此处理循环。当输入队列关闭或节点停止时,它会退出。
setBoundingBox
Python
1def setBoundingBox(bbox: tuple[int, int, int, int]):
设置边界框。参数
  • bbox (tuple[int, int, int, int]): 边界框
setConfidenceThreshold
Python
1def setConfidenceThreshold(threshold: float):
设置置信度分数阈值。参数
  • threshold (float): 置信度分数阈值。
setIouThreshold
Python
1def setIouThreshold(iou_threshold: float):
设置交并比阈值。参数
  • iou_threshold (float): 交并比阈值。
setMaskConfidence
Python
1def setMaskConfidence(mask_conf: float):
设置掩码置信度阈值。参数
  • mask_conf (float): 掩码置信度阈值。
setMaskOutputs
Python
1def setMaskOutputs(mask_outputs: list[str]):
设置掩码输出。参数
  • mask_outputs (list[str]): 掩码输出
setNumClasses
Python
1def setNumClasses(n_classes: int):
设置模型中的类别数量。参数
  • n_classes (int): 模型中的类别数量。
setPointLabel
Python
1def setPointLabel(point_label: int):
设置点标签。参数
  • point_label (int): 点标签
setPoints
Python
1def setPoints(points: tuple[int, int]):
设置点。参数
  • points (tuple[int, int]): 点
setPrompt
Python
1def setPrompt(prompt: str):
设置提示类型。参数
  • prompt (str): 提示类型
setProtosOutput
Python
1def setProtosOutput(protos_output: str):
设置原型输出。参数
  • protos_output (str): 原型输出
setYoloOutputs
Python
1def setYoloOutputs(yolo_outputs: list[str]):
设置 YOLO 输出。参数
  • yolo_outputs (list[str]): YOLO 输出

属性

bbox
边界框。
conf_threshold
检测对象的置信度分数阈值。
iou_threshold
非极大值抑制阈值。
mask_conf
掩码置信度阈值。
mask_outputs
掩码输出的名称。
n_classes
模型中的类别数量。
point_label
点标签。
points
点。
prompt
提示类型。
protos_output
原型输出的名称。
yolo_outputs
YOLO 输出的名称。