nvidia.dali.fn.segmentation.select_masks#

nvidia.dali.fn.segmentation.select_masks(__mask_ids, __polygons, __vertices, /, *, bytes_per_sample_hint=[0], preserve=False, reindex_masks=False, device=None, name=None)#

根据掩码 ID 选择多边形的子集。

该运算符需要三个输入,描述属于不同掩码 ID 的多个分割掩码多边形,以及选定的掩码 ID 列表。

每个样本可以包含属于不同掩码的多个多边形,并且每个多边形可以由任意数量的顶点(至少 3 个)组成。掩码多边形由输入 polygonsvertices 描述,运算符生成输出 polygonsvertices,其中仅存在与选定掩码关联的多边形。

注意

polygonsvertices 的格式与 COCOReader 生成的格式相同。

示例

让我们假设以下输入掩码,其中符号坐标用于更清晰的示例

polygons = [[0, 0, 3], [1, 3, 7], [2, 7, 10]]
vertices = [[x0, y0], [x1, y1], [x2, y2], [x3, y3], [x4, y4], [x5, y5],
            [x6, y6], [x7, y7], [x8, y8], [x9, y9]]

示例 1:选择 ID 为 1 的单个掩码,保持原始 ID

mask_ids = [1], :paramref:`~nvidia.dali.fn.segmentation.select_masks.reindex_masks` = False
out_polygons = [[1, 0, 4]]
out_vertices = [[x3, y3], [x4, y4], [x5, y5], [x6, y6]]

示例 2:选择三个掩码中的两个,将掩码 ID 替换为它们在 mask_ids 输入中出现的索引

mask_ids = [2, 0]
reindex_masks = True
out_polygons = [[0, 3, 6], [1, 0, 3]]
out_vertices = [[x0, y0], [x1, y1], [x2, y2], [x7, y7], [x8, y8], [x9, y9]]
支持的后端
  • ‘cpu’

参数:
  • __mask_ids (1D TensorList of int) – 要选择的掩码的标识符列表。列表不应包含重复项。

  • __polygons (2D TensorList of int) –

    多边形,由 3 列描述

    [[mask_id0, start_vertex_idx0, end_vertex_idx0],
     [mask_id1, start_vertex_idx1, end_vertex_idx1],
     ...,
     [mask_idn, start_vertex_idxn, end_vertex_idxn],]
    

    其中 mask_id 是此多边形所属的掩码的标识符,[start_vertex_idx, end_vertex_idx) 描述了属于此多边形的 vertices 中的索引范围。

  • __vertices (2D TensorList) –

    以交错格式存储的顶点数据

    [[x0, y0, ...],
     [x1, y1, ...],
     ... ,
     [xn, yn, ...]]
    

    该运算符接受具有任意数量坐标的顶点。

关键词参数:
  • bytes_per_sample_hint (int 或 list of int, optional, default = [0]) –

    输出大小提示,以字节/样本为单位。

    如果指定,则预先分配位于 GPU 或分页锁定主机内存中的运算符输出,以适应此大小的样本批次。

  • preserve (bool, optional, default = False) – 阻止运算符从图中移除,即使其输出未使用。

  • reindex_masks (bool, optional, default = False) – 如果设置为 True,输出掩码 ID 将替换为它们在 mask_ids 输入中出现的索引。