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

本页目录

  • 类
  • InstanceSegKeypointVisualizer
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

instance_seg_keypoint_visualizer

最后更新
Python API: luxonis_train.attached_modules.visualizers.instance_seg_keypoint_visualizer在同一图像上绘制实例掩码、边界框和关键点。

类

InstanceSegKeypointVisualizer

实例掩码、边界框、关键点和目标的视觉化工具。
https://raw.githubusercontent.com/luxonis/luxonis-train/e542cf0efa20a0fc5c781ff505d699031cb0d228/media/example_viz/instance_seg_keypoints.png
左图显示目标。右图显示预测。
  • 输入::
    • prediction_canvas, target_canvas (Tensor): [B, 3, H, W]
    • boundingbox (list[Tensor]): 每张图像 [Mi, 6],[x1, y1, x2, y2, conf, class],像素
    • instance_segmentation (list[Tensor]): 每张图像 [Mi, H, W],二进制
    • keypoints (list[Tensor]): 每张图像 [Mi, nkeypoints, 3],(x, y, conf),像素
    • target_boundingbox (Tensor | None): [N, 6],[batch, class, x, y, w, h],xywh 归一化
    • target_instance_segmentation (Tensor | None): [N, H, W],每个目标框一个
    • target_keypoints (Tensor | None): [N, 1 + 3**n*keypoints],[batch, x, y, v, ...],归一化
  • 输出::
    • Tensor | tuple[Tensor, Tensor]: [B, 3, H, W],当给定任何目标时,为 (targets, predictions) 对

方法

init
Python
1def __init__(labels: dict[int, str] | list[str] | None = None, draw_labels: bool = True, draw_scores: bool = False, colors: dict[str, Color] | list[Color] | None = None, fill: bool = False, width: int | None = None, font: str | None = None, font_size: int | None = None, alpha: float = 0.6, visibility_threshold: float = 0.5, connectivity: list[tuple[int, int]] | None = None, visible_color: Color = 'red', nonvisible_color: Color | None = None, radius: int | None = None, draw_indices: bool = False, **kwargs):
初始化视觉化工具并解析类名和颜色。参数
  • labels (dict[int, str] | list[str] | None): 要绘制的类名。字典将类索引映射到名称。列表按位置映射。当为 None 或空时,名称来自节点的 classes,因此视觉化工具需要一个 node。
  • draw_labels (bool): 是否在每个框旁边绘制类名。适用于预测和目标。
  • draw_scores (bool): 是否在每个预测框的标签中写入其置信度,保留两位小数。仅适用于预测。如果没有 draw_labels,标签就是置信度本身。
  • colors (dict[str, Color] | list[Color] | None): 掩码和框的颜色。字典将类名映射到颜色。列表按类索引映射。当为 None 时,每个类都会从 get_color 获取一个不同的颜色,并以其索引作为种子。
  • fill (bool): 绘图方法不读取它。
  • width (int | None): 框的线宽,以像素为单位。当为 None 或 0 时,宽度是较小画布边长百分之一,向下取整,且至少为 1。
  • font (str | None): 绘图方法不读取它。
  • font_size (int | None): 绘图方法不读取它。
  • alpha (float): 掩码的不透明度,从 0(透明)到 1(不透明)。
  • visibility_threshold (float): 可见预测关键点的最低置信度。KeypointVisualizer.draw_predictions 说明了视觉化工具如何绘制其他关键点。
  • connectivity (list[tuple[int, int]] | None): 用线连接的关键点索引对,即骨架。适用于预测和目标。None 不绘制线条。
  • visible_color (Color): 可见预测关键点和所有目标关键点的颜色。
  • nonvisible_color (Color | None): 低于 visibility_threshold 的预测关键点的颜色。当为 None 时,视觉化工具不会在它们的坐标处绘制它们。
  • radius (int | None): 关键点的半径,以像素为单位。当为 None 时,forward 会根据每个画布的大小选择它。
  • draw_indices (bool): 是否在每个关键点旁边写入其索引。KeypointVisualizer.draw_targets 说明了何时这会为目标关键点引发 RuntimeError。
  • **kwargs: 转发给 BaseVisualizer 的关键字参数,例如 scale 和 node。
forward
Python
1def forward(prediction_canvas: Tensor, target_canvas: Tensor, boundingbox: list[Tensor], instance_segmentation: list[Tensor], keypoints: list[Tensor], target_boundingbox: Tensor | None, target_instance_segmentation: Tensor | None, target_keypoints: Tensor | None) -> tuple[Tensor, Tensor] | Tensor:
绘制预测的掩码、边界框和关键点,以及给定时的目标。InstanceSegmentationVisualizer.draw_predictions 绘制掩码和边界框,KeypointVisualizer.draw_predictions 在其上方绘制关键点。目标从 target_canvas 开始:当 radius 为 None 时,半径来自每个画布的大小。当两边都小于 96 像素时为 1,当一边大于 512 像素时为 5,否则为 2。参数
  • prediction_canvas (Tensor): 形状为 [B, 3, H, W] 的 uint8 图像,用于绘制预测。
  • target_canvas (Tensor): 形状为 [B, 3, H, W] 的 uint8 图像,用于绘制目标。
  • boundingbox (list[Tensor]): 每张图像一个张量,形状为 [M_i, 6],行格式为 [x1, y1, x2, y2, conf, class],以像素为单位。
  • instance_segmentation (list[Tensor]): 每张图像一个张量,形状为 [M_i, H_0, W_0],每个框一个二进制掩码。H_0 和 W_0 是 scale 调整大小前的图像大小。
  • keypoints (list[Tensor]): 每张图像一个张量,形状为 [M_i, K, 3]。每个关键点为 (x, y, confidence),x 和 y 以像素为单位。
  • target_boundingbox (Tensor | None): 形状为 [N, 6] 的框,行格式为 [batch_index, class, x, y, w, h],xywh 归一化到 [0, 1]。当批次没有 boundingbox 标签时为 None。
  • target_instance_segmentation (Tensor | None): 形状为 [N, H_0, W_0] 的二进制掩码,每个目标框一个。当批次没有 instance_segmentation 标签时为 None。
  • target_keypoints (Tensor | None): 形状为 [N, 1 + 3 * K] 的关键点,行格式为 [batch_index, x_1, y_1, v_1, ..., v_K]。坐标归一化到 [0, 1]。当批次没有 keypoints 标签时为 None。
返回
  • tuple[Tensor, Tensor] | Tensor: 当设置了三个目标中的任何一个时,返回绘制图像的 (targets, predictions) 对;否则只返回预测图像。当只设置了 target_boundingbox 和 target_instance_segmentation 中的一个,且 target_keypoints 为 None 时,目标图像就是 target_canvas 本身。

属性

supported_tasks