vis4d.op.box.anchor.point_generator

Point generator for 2D bounding boxes.

Modified from: https://github.com/open-mmlab/mmdetection/blob/master/mmdet/core/anchor/point_generator.py

Classes

MlvlPointGenerator(strides[, offset])

Standard points generator for multi-level feature maps.

class MlvlPointGenerator(strides, offset=0.5)[source]

Standard points generator for multi-level feature maps.

Used for 2D points-based detectors.

Parameters:
  • strides (list[int] | list[tuple[int, int]]) – Strides of anchors in multiple feature levels in order (w, h).

  • offset (float) – The offset of points, the value is normalized with corresponding stride. Defaults to 0.5.

Init.

grid_priors(featmap_sizes, dtype=torch.float32, device=device(type='cuda'), with_stride=False)[source]

Generate grid points of multiple feature levels.

Parameters:
  • featmap_sizes (list[tuple[int, int]]) – List of feature map sizes in multiple feature levels, each (H, W).

  • dtype (torch.dtype) – Dtype of priors. Defaults to torch.float32.

  • device (torch.device) – The device where the anchors will be put on. Defaults to torch.device(“cuda”).

  • with_stride (bool) – Whether to concatenate the stride to the last dimension of points. Defaults to False,

Returns:

Points of multiple feature levels.

The sizes of each tensor should be (N, 2) when with stride is False, where N = width * height, width and height are the sizes of the corresponding feature level, and the last dimension 2 represent (coord_x, coord_y), otherwise the shape should be (N, 4), and the last dimension 4 represent (coord_x, coord_y, stride_w, stride_h).

Return type:

list[torch.Tensor]

single_level_grid_priors(featmap_size, level_idx, dtype=torch.float32, device=device(type='cuda'), with_stride=False)[source]

Generate grid Points of a single level.

Note

This function is usually called by method self.grid_priors.

Parameters:
  • featmap_size (tuple[int, int]) – Size of the feature maps, (H, W).

  • level_idx (int) – The index of corresponding feature map level.

  • dtype (torch.dtype) – Dtype of priors. Defaults to torch.float32.

  • device (torch.device) – The device where the tensors will be put on. Defaults to torch.device(“cuda”).

  • with_stride (bool) – Concatenate the stride to the last dimension of points. Defaults to False,

Returns:

Points of single feature levels.

The shape of tensor should be (N, 2) when with stride is False, where N = width * height, width and height are the sizes of the corresponding feature level, and the last dimension 2 represent (coord_x, coord_y), otherwise the shape should be (N, 4), and the last dimension 4 represent (coord_x, coord_y, stride_w, stride_h).

Return type:

Tensor

single_level_valid_flags(featmap_size, valid_size, device=device(type='cuda'))[source]

Generate the valid flags of points of a single feature map.

Parameters:
  • featmap_size (tuple[int, int]) – The size of feature maps, (H, W).

  • valid_size (tuple[int, int]) – The valid size of the feature maps, (H, W).

  • device (torch.device, optional) – The device where the flags will be put on. Defaults to torch.device(“cuda”).

Returns:

The valid flags of each points in a single level

feature map.

Return type:

torch.Tensor

valid_flags(featmap_sizes, pad_shape, device=device(type='cuda'))[source]

Generate valid flags of points of multiple feature levels.

Parameters:
  • featmap_sizes (list[tuple[int, int]]) – List of feature map sizes in multiple feature levels, each (H, W).

  • pad_shape (tuple[int, int]) – The padded shape of the image, (H, W).

  • device (torch.device) – The device where the anchors will be put on. Defaults to torch.device(“cuda”).

Returns:

Valid flags of points of multiple levels.

Return type:

list(torch.Tensor)

property num_base_priors: list[int]

Number of points at a point on the feature grid.

property num_levels: int

Number of feature levels.