| Files | Last commit | Last update |
|---|---|---|
| 2 months ago | ||
| 2 months ago | ||
| 23 days ago | ||
| 23 days ago | ||
| 1 month ago | ||
| 23 days ago | ||
| 1 month ago | ||
| 17 days ago |
ROIPooling
English | 简体中文
Applicable Products
| Product | Support |
|---|---|
| Ascend 950PR&950DT products | √ |
| Atlas A3 products | √ |
| Atlas A2 products | √ |
| Atlas 200I/500 A2 inference products | × |
| Atlas inference products | × |
| Atlas training products | × |
Function
-
Operator function: Performs max pooling on the input feature map by ROI (Region of Interest) regions and outputs pooling results of a fixed size, used for tasks such as object detection.
-
Formula:
For each ROI n (rois[n] = [batch_idx, x1, y1, x2, y2]), channel c, and pooling position (ph,pw):
1. ROI coordinate mapping (uses separate h/w scaling factors, roundf rounds to int, and the end coordinates have no +1 offset):
roi_startw=round(x1⋅spatial_scale_w),roi_starth=round(y1⋅spatial_scale_h)\text{roi\_start}_w = \text{round}(x1 \cdot \text{spatial\_scale\_w}), \quad \text{roi\_start}_h = \text{round}(y1 \cdot \text{spatial\_scale\_h})
roi_endw=round(x2⋅spatial_scale_w),roi_endh=round(y2⋅spatial_scale_h)\text{roi\_end}_w = \text{round}(x2 \cdot \text{spatial\_scale\_w}), \quad \text{roi\_end}_h = \text{round}(y2 \cdot \text{spatial\_scale\_h})
All the preceding coordinates are integers (int type); the +1 offset is on the ROI size (see below), not on the coordinates.
2. ROI size (int arithmetic, +1 on width/height, malformed ROIs are forced to be non-empty):
roi_w=max(roi_endw−roi_startw+1,1),roi_h=max(roi_endh−roi_starth+1,1)\text{roi\_w} = \max(\text{roi\_end}_w - \text{roi\_start}_w + 1, 1), \quad \text{roi\_h} = \max(\text{roi\_end}_h - \text{roi\_start}_h + 1, 1)
3. Bin splitting and boundary clipping (bin_size is float, based on the int roi_w/roi_h):
bin_sizew=roi_wpooled_w,bin_sizeh=roi_hpooled_h\text{bin\_size}_w = \frac{\text{roi\_w}}{\text{pooled\_w}}, \quad \text{bin\_size}_h = \frac{\text{roi\_h}}{\text{pooled\_h}}
binx1=clamp(⌊pw⋅bin_sizew⌋+roi_startw,0,W)\text{bin}_{x1} = \text{clamp}(\lfloor pw \cdot \text{bin\_size}_w \rfloor + \text{roi\_start}_w, 0, W)
binx2=clamp(⌈(pw+1)⋅bin_sizew⌉+roi_startw,0,W)\text{bin}_{x2} = \text{clamp}(\lceil (pw+1) \cdot \text{bin\_size}_w \rceil + \text{roi\_start}_w, 0, W)
(The same applies to the y direction, clamped to [0, H])
floor/ceil is based on the relative offset (excluding roi_start), and then the integer roi_start is added.
4. Max pooling (empty bins output 0):
y[n,c,ph,pw]={0if binx2≤binx1 or biny2≤biny1maxh,w∈[biny1,biny2)×[binx1,binx2)x[batch_idx,c,h,w]otherwisey[n, c, ph, pw] = \begin{cases} 0 & \text{if } \text{bin}_{x2} \le \text{bin}_{x1} \text{ or } \text{bin}_{y2} \le \text{bin}_{y1} \\ \max_{h, w \in [\text{bin}_{y1}, \text{bin}_{y2}) \times [\text{bin}_{x1}, \text{bin}_{x2})} x[\text{batch\_idx}, c, h, w] & \text{otherwise} \end{cases}
The +1 offset is on the ROI size (roi_width = roi_end - roi_start + 1), which is the common standard of ROI Pooling (originating from Fast R-CNN)
Parameters
| Parameter name | Input/Output/Attribute | Description | Data type | Data format |
|---|---|---|---|---|
| x | Input | Feature map, with shape [N,C,H,W]; it is x in the formulas. | FLOAT, FLOAT16 | ND |
| rois | Input | ROI boxes, with shape [K,5]; each row is [batch_idx,x1,y1,x2,y2]. | FLOAT, FLOAT16 | ND |
| roi_actual_num | Input | Actual number of ROIs of each batch; optional input that does not participate in the computation in the current version. | INT32 | ND |
| y | Output | Pooling result, with shape [K,C,pooled_h,pooled_w]; it is y in the formulas. | FLOAT, FLOAT16 | ND |
| pooled_h | Attribute | Height of the pooling output. | Int | - |
| pooled_w | Attribute | Width of the pooling output. | Int | - |
| spatial_scale_h | Attribute | Scaling factor in the height direction. | Float | - |
| spatial_scale_w | Attribute | Scaling factor in the width direction. | Float | - |
Constraints
- The input x supports only 4 dimensions [N,C,H,W].
- The input rois supports only 2 dimensions [K,5]; each row is [batch_idx,x1,y1,x2,y2].
- roi_actual_num is an optional input and does not participate in the computation in the current version.
- pooled_h and pooled_w must be greater than 0.
- spatial_scale_h and spatial_scale_w must be greater than 0.
- The dtypes of x and rois must be consistent.
- The shape of the output y is [K,C,pooled_h,pooled_w].
- ROI coordinates are rounded to int with roundf, and the +1 offset is on the ROI size (roi_width = roi_end - roi_start + 1).
- Malformed ROIs are forced to be non-empty, and roi_size takes max(size,1) (int arithmetic).
- Empty bins output 0.
Invocation Description
| Invocation method | Invocation sample | Description |
|---|---|---|
| Graph-mode invocation | test_geir_roi_pooling | See operator invocation to complete operator compilation and verification. |