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

本页目录

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

classification_visualizer

最后更新
Python API: luxonis_train.attached_modules.visualizers.classification_visualizer绘制预测的类别名称、标签类别名称和类别概率的条形图。

类

ClassificationVisualizer

可视化分类预测和可选标签。
https://raw.githubusercontent.com/luxonis/luxonis-train/e542cf0efa20a0fc5c781ff505d699031cb0d228/media/example_viz/class.png
图像显示了目标类别和预测类别。图表显示了每个类别的预测概率。
  • 输入::
    • prediction_canvas, target_canvas (Tensor): [B, 3, H, W]
    • predictions (Tensor): [B, nclasses] logits
    • target (Tensor | None): [B, nclasses] one-hot,或 multilabel 的 multi-hot
  • 输出::
    • Tensor | tuple[Tensor, Tensor]: [B, 3, H, W],当设置 include_plot 时带有概率图

方法

init
Python
1def __init__(include_plot: bool = True, font_scale: float | None = None, color: tuple[int, int, int] = (255, 0, 0), thickness: int = 2, multilabel: bool = False, **kwargs):
初始化可视化器并存储文本和绘图选项。参数
  • include_plot (bool): forward 是否也返回类别概率的条形图作为第二张图像。默认为 True。
  • font_scale (float | None): OpenCV 文本的字体比例。当为 None 时,dynamically_determine_font_scale 从图像大小推导出比例。文本行位于图像高度的 15% 和 25% 处。值为 0 时选择相同的行位置,但保持字体比例为 0 并将厚度设置为 1。任何其他值按给定应用,与 thickness 一起,并将文本行放置在 y = 50 和 y = 75 像素处。
  • color (tuple[int, int, int]): 文本的 RGB 颜色。默认为 (255, 0, 0),红色。
  • thickness (int): 文本描边的厚度。当推导出的字体比例小于 1 时,厚度变为 1。默认为 2。
  • multilabel (bool): 任务是否为多标签。当为 True 时,文本列出每个原始值大于 0.5 的类别,图表显示 sigmoid 概率。当为 False 时,文本显示值最高的类别,图表显示 softmax 概率。默认为 False。
  • **kwargs: 转发给 BaseVisualizer 的关键字参数,例如 scale 和 node。
forward
Python
1def forward(prediction_canvas: Tensor, target_canvas: Tensor, predictions: Tensor, target: Tensor | None) -> Tensor | tuple[Tensor, Tensor]:
在图像上写入类别名称并绘制概率。对于每张图像,该方法在目标画布图像的副本上写入 Pred: <name>。当给定 target 时,它在其上方写入 GT: <name>。两行都使用 color 以及 font_scale 选择的字体比例和厚度。当 include_plot 为 True 时,它还会渲染一个类别概率的条形图,其大小与预测画布相同。参数
  • prediction_canvas (Tensor): 形状为 [B, 3, H, W] 的图像。该方法仅读取其形状、dtype 和设备,用于绘图。
  • target_canvas (Tensor): 形状为 [B, 3, H, W] 的图像,用于写入文本。
  • predictions (Tensor): 形状为 [B, n_classes] 的 logits。
  • target (Tensor | None): 形状为 [B, n_classes] 的 one-hot 标签,或 multilabel 的 multi-hot。当批次没有 classification 标签时为 None;此时该方法不写入 GT 行。
返回
  • Tensor | tuple[Tensor, Tensor]: 当 include_plot 为 True 时,返回 (text_images, plots) 对,两者形状均为 [B, 3, H, W]。否则只返回文本图像。

属性

supported_tasks