In object detection, different regions of interest (ROIs) have different sizes, but downstream classifiers need fixed-size inputs. ROI Pooling extracts a fixed-size feature map from each region by dividing it into bins and applying max pooling within each bin.
Given a 2D feature map, a list of ROIs (bounding boxes in feature map coordinates), and a target output size, apply ROI Pooling to produce a fixed-size output for each ROI.
For each ROI [x1, y1, x2, y2] with height roi_h = y2 - y1 and width roi_w = x2 - x1:
Return a list of 2D grids, one per ROI.
Input: feature_map = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], rois = [[0,0,4,4]], output_size = 2
Output: [[[6, 8], [14, 16]]]
The 4x4 ROI splits evenly into four 2x2 bins. Max of each: top-left=6, top-right=8, bottom-left=14, bottom-right=16.
Input: feature_map = [[10,20,30],[40,50,60],[70,80,90]], rois = [[0,0,3,3]], output_size = 2
Output: [[[10, 30], [70, 90]]]
3x3 ROI into 2x2 output: bins are uneven (floor-based). Top-left bin covers 1 cell (10), top-right covers 2 (20,30→30), bottom-left covers 2 (40,70→70), bottom-right covers 4 (50,60,80,90→90).
Compute bin boundaries using floor(i * roi_size / output_size) to handle uneven division.
When the ROI is smaller than the output size, bins may collapse to zero width. Always ensure at least one pixel per bin.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
In object detection, different regions of interest (ROIs) have different sizes, but downstream classifiers need fixed-size inputs. ROI Pooling extracts a fixed-size feature map from each region by dividing it into bins and applying max pooling within each bin.
Given a 2D feature map, a list of ROIs (bounding boxes in feature map coordinates), and a target output size, apply ROI Pooling to produce a fixed-size output for each ROI.
For each ROI [x1, y1, x2, y2] with height roi_h = y2 - y1 and width roi_w = x2 - x1:
Return a list of 2D grids, one per ROI.
Input: feature_map = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], rois = [[0,0,4,4]], output_size = 2
Output: [[[6, 8], [14, 16]]]
The 4x4 ROI splits evenly into four 2x2 bins. Max of each: top-left=6, top-right=8, bottom-left=14, bottom-right=16.
Input: feature_map = [[10,20,30],[40,50,60],[70,80,90]], rois = [[0,0,3,3]], output_size = 2
Output: [[[10, 30], [70, 90]]]
3x3 ROI into 2x2 output: bins are uneven (floor-based). Top-left bin covers 1 cell (10), top-right covers 2 (20,30→30), bottom-left covers 2 (40,70→70), bottom-right covers 4 (50,60,80,90→90).
Compute bin boundaries using floor(i * roi_size / output_size) to handle uneven division.
When the ROI is smaller than the output size, bins may collapse to zero width. Always ensure at least one pixel per bin.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number