mindspore.ops.ROIAlign

class mindspore.ops.ROIAlign(pooled_height, pooled_width, spatial_scale, sample_num=2, roi_end_mode=1)[source]

Computes the Region of Interest (RoI) Align operator.

The operator computes the value of each sampling point by bilinear interpolation from the nearby grid points on the feature map. No quantization is performed on any coordinates involved in the RoI, its bins, or the sampling points. The details of (RoI) Align operator are described in Mask R-CNN.

Parameters
  • pooled_height (int) – The output features height.

  • pooled_width (int) – The output features width.

  • spatial_scale (float) – A scaling factor that maps the raw image coordinates to the input feature map coordinates. Suppose the height of a RoI is ori_h in the raw image and fea_h in the input feature map, the spatial_scale must be fea_h / ori_h.

  • sample_num (int) – Number of sampling points. Default: 2 .

  • roi_end_mode (int) – Number must be 0 or 1. If roi_end_mode=0, use the legacy implementation. If roi_end_mode=1, end pixel of the roi_box will be shifted by +1*spatial_scale. Default: 1 .

Inputs:
  • features (Tensor) - The input features, whose shape must be \((N, C, H, W)\).

  • rois (Tensor) - The shape is \((rois\_n, 5)\). With data type of float16 or float32. rois_n represents the number of RoI. The size of the second dimension must be 5 and the 5 colunms are \((image\_index, top\_left\_x, top\_left\_y, bottom\_right\_x, bottom\_right\_y)\). image_index represents the index of image. top_left_x and top_left_y represent the x, y coordinates of the top left corner of corresponding RoI, respectively. bottom_right_x and bottom_right_y represent the x, y coordinates of the bottom right corner of corresponding RoI, respectively.

Outputs:

Tensor, the shape is \((rois\_n, C, pooled\_height, pooled\_width)\).

Raises
  • TypeError – If pooled_height, pooled_width, sample_num or roi_end_mode is not an int.

  • TypeError – If spatial_scale is not a float.

  • TypeError – If features or rois is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> features = Tensor(np.array([[[[1., 2.], [3., 4.]]]]), mindspore.float32)
>>> rois = Tensor(np.array([[0, 0.2, 0.3, 0.2, 0.3]]), mindspore.float32)
>>> roi_align = ops.ROIAlign(2, 2, 0.5, 2)
>>> output = roi_align(features, rois)
>>> print(output)
[[[[1.775 2.025]
   [2.275 2.525]]]]