Skip to content

Commit 973f898

Browse files
authored
[cherry-pick] add RoI Align cn doc (#3948)
* add roi_align doc * fix doc for data type * fix doc format * fix comments
1 parent b9cfae5 commit 973f898

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _cn_api_paddle_vision_ops_RoIAlign:
2+
3+
RoIAlign
4+
-------------------------------
5+
6+
.. py:class:: paddle.vision.ops.RoIAlign(output_size, spatial_scale=1.0)
7+
8+
该接口用于构建一个 ``RoIAlign`` 类的可调用对象。请参见 :ref:`cn_api_paddle_vision_ops_roi_align` API。
9+
10+
参数
11+
:::::::::
12+
- output_size (int|Tuple(int, int)) - 池化后输出的尺寸(H, W),数据类型为int32。如果output_size是单个int类型整数,则H和W都与其相等。
13+
- spatial_scale (float, 可选) - 空间比例因子,用于将boxes中的坐标从其输入尺寸按比例映射到输入特征图的尺寸,默认值1.0。
14+
15+
形状
16+
:::::::::
17+
- x: 4-D Tensor,形状为(N, C, H, W)。数据类型为float32或float64。
18+
- boxes: 2-D Tensor,形状为(boxes_num, 4)。
19+
- boxes_num: 1-D Tensor。数据类型为int32。
20+
- output: 4-D tensor,形状为(RoI数量,输出通道数,池化后高度,池化后宽度)。输出通道数等于输入通道数/(池化后高度 * 池化后宽度)。
21+
22+
代码示例
23+
:::::::::
24+
25+
.. code-block:: python
26+
27+
import paddle
28+
from paddle.vision.ops import RoIAlign
29+
30+
data = paddle.rand([1, 256, 32, 32])
31+
boxes = paddle.rand([3, 4])
32+
boxes[:, 2] += boxes[:, 0] + 3
33+
boxes[:, 3] += boxes[:, 1] + 4
34+
boxes_num = paddle.to_tensor([3]).astype('int32')
35+
roi_align = RoIAlign(output_size=(4, 3))
36+
align_out = roi_align(data, boxes, boxes_num)
37+
assert align_out.shape == [3, 256, 4, 3]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. _cn_api_paddle_vision_ops_roi_align:
2+
3+
roi_align
4+
-------------------------------
5+
6+
.. py:function:: paddle.vision.ops.roi_align(input, boxes, boxes_num, output_size, spatial_scale=1.0, aligned=True, name=None)
7+
8+
RoI Align是在指定输入的感兴趣区域上执行双线性插值以获得固定大小的特征图(例如7*7),如 Mask R-CNN论文中所述, 请参阅 https://arxiv.org/abs/1703.06870。
9+
10+
参数
11+
:::::::::
12+
- x (Tensor) - 输入的特征图,形状为(N, C, H, W)。数据类型为float32或float64。
13+
- boxes (Tensor) - 待执行池化的RoIs(Regions of Interest)的框坐标。它应当是一个形状为(boxes_num, 4)的2-D Tensor,以[[x1, y1, x2, y2], ...]的形式给出。其中(x1, y1)是左上角的坐标值,(x2, y2)是右下角的坐标值。
14+
- boxes_num (Tensor) - 该batch中每一张图所包含的框数量。数据类型为int32。
15+
- output_size (int|Tuple(int, int)) - 池化后输出的尺寸(H, W),数据类型为int32。如果output_size是单个int类型整数,则H和W都与其相等。
16+
- spatial_scale (float, 可选) - 空间比例因子,用于将boxes中的坐标从其输入尺寸按比例映射到input特征图的尺寸。
17+
- aligned (bool, 可选)- 默认值为True,表示像素移动框将其坐标移动-0.5,以便与两个相邻像素索引更好地对齐。如果为False,则是使用遗留版本的实现。
18+
- name (str, 可选)- 默认值为None。一般用户无需设置,具体用法请参见 :ref:`api_guide_Name`。
19+
20+
返回
21+
:::::::::
22+
Tensor,池化后的RoIs,为一个形状是(RoI数量,输出通道数,池化后高度,池化后宽度)的4-D Tensor。输出通道数等于输入通道数/(池化后高度 * 池化后宽度)。
23+
24+
代码示例
25+
:::::::::
26+
27+
.. code-block:: python
28+
29+
import paddle
30+
from paddle.vision.ops import roi_align
31+
32+
data = paddle.rand([1, 256, 32, 32])
33+
boxes = paddle.rand([3, 4])
34+
boxes[:, 2] += boxes[:, 0] + 3
35+
boxes[:, 3] += boxes[:, 1] + 4
36+
boxes_num = paddle.to_tensor([3]).astype('int32')
37+
align_out = roi_align(data, boxes, boxes_num=boxes_num, output_size=3)
38+
assert align_out.shape == [3, 256, 3, 3]

0 commit comments

Comments
 (0)