megengine.functional.nn.roi_align

roi_align(inp, rois, output_shape, mode='average', spatial_scale=1.0, sample_points=2, aligned=True)[源代码]

Applies roi align on input feature.

参数
  • inp (Tensor) – tensor that represents the input feature, shape is (N, C, H, W).

  • rois (Tensor) – N, 5)` boxes. First column is the box index. The other 4 columns are xyxy.

  • output_shape (Union[int, tuple, list]) – height, width)` shape of output rois feature.

  • mode (str) – max” or “average”, use max/average align just like max/average pooling. Default: “average”

  • spatial_scale (float) – scale the input boxes by this number. Default: 1.0

  • sample_points (Union[int, tuple, list]) – number of inputs samples to take for each output sample. 0 to take samples densely. Default: 2

  • aligned (bool) – wheather to align the input feature, with aligned=True, we first appropriately scale the ROI and then shift it by -0.5. Default: True

返回类型

Tensor

返回

output tensor.

实际案例

import numpy as np
from megengine import tensor
import megengine.functional as F

np.random.seed(42)
inp = tensor(np.random.randn(1, 1, 128, 128))
rois = tensor(np.random.random((4, 5)))
y = F.vision.roi_align(inp, rois, (2, 2))
print(y.numpy()[0].round(decimals=4))

Outputs:

[[[0.175  0.175 ]
  [0.1359 0.1359]]]