fastsam
最后更新
depthai_nodes.node.parsers.fastsam类
FastSAMParser
注意
发出
dai.SegmentationMask 消息。dai.SegmentationMask 消息包含给定提示的分割掩码结果。方法
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]:注意
使用 depthai_nodes.node.parsers.utils.fastsam.compute_fastsam_mask;有关张量布局和验证详细信息,请参阅该辅助函数。
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_outputs(list[str]): YOLO 输出