nvidia.dali.fn.segmentation.select_masks

nvidia.dali.fn.segmentation.select_masks(*inputs, **kwargs)

Selects a subset of polygons by their mask ids.

The operator expects three inputs describing multiple segmentation mask polygons belonging to different mask ids and a list of selected mask ids.

Each sample can contain several polygons belonging to different masks, and each polygon can be composed by an arbitrary number of vertices (at least 3). The masks polygons are described by the inputs polygons and vertices and the operator produces output polygons and vertices where only the polygons associated with the selected masks are present.

Note

The format of polygons and vertices is the same as produced by COCOReader.

Examples:

Let us assume the following input mask, where symbolic coordinates are used for a clearer example:

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]]

Example 1: Selecting a single mask with id 1, maintaining the original id:

mask_ids = [1], ``reindex_masks`` = False
out_polygons = [[1, 0, 4]]
out_vertices = [[x3, y3], [x4, y4], [x5, y5], [x6, y6]]

Example 2: Selecting two out of the three masks, replacing the mask ids with the indices at which they appeared in mask_ids input:

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]]
Supported backends
  • ‘cpu’

Parameters:
  • mask_ids (1D TensorList of int) – List of identifiers of the masks to be selected. The list should not contain duplicates.

  • polygons (2D TensorList of int) –

    Polygons, described by 3 columns:

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

    with mask_id being the identifier of the mask this polygon belongs to, and [start_vertex_idx, end_vertex_idx) describing the range of indices from vertices that belong to this polygon.

  • vertices (2D TensorList) –

    Vertex data stored in interleaved format:

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

    The operator accepts vertices with arbitrary number of coordinates.

Keyword Arguments:
  • bytes_per_sample_hint (int or list of int, optional, default = [0]) –

    Output size hint, in bytes per sample.

    If specified, the operator’s outputs residing in GPU or page-locked host memory will be preallocated to accommodate a batch of samples of this size.

  • preserve (bool, optional, default = False) – Prevents the operator from being removed from the graph even if its outputs are not used.

  • reindex_masks (bool, optional, default = False) – If set to True, the output mask ids are replaced with the indices at which they appeared in mask_ids input.

  • seed (int, optional, default = -1) –

    Random seed.

    If not provided, it will be populated based on the global seed of the pipeline.