ROI Pooling
Region of Interest Pooling
Fundamental technique in object-detection architectures, popularized by classic models like Fast R-CNN.
What it is and Practical Context
ROI Pooling (Region of Interest Pooling) is a crucial operation in neural networks. Its goal is to extract fixed-size feature maps from regions of interest (ROIs) that have varying sizes.
In region-based object detection (Region-Based CNNs), an image first passes through a convolutional network (backbone) that generates a global feature map. In parallel, algorithms suggest “boxes” (ROIs) where objects might be. Because these ROIs have different proportions and sizes, they cannot be directly fed into Fully Connected Layers, which require fixed-size inputs. ROI Pooling solves this by dividing the projected ROI into a fixed grid (e.g., ) and extracting the maximum value (Max Pooling) from each subdivision.
🧮 Mathematical Foundation (Dense)
Let a feature map be and a region of interest bounded by continuous coordinates projected onto the feature map from the original image (with a scaling factor ).
The projection undergoes a first rounding (quantization) to obtain discrete coordinates in the feature map:
Eq. 1: Projection of continuous coordinates onto the discrete grid of the feature map.
Where:
- : continuous coordinates of the region of interest in the original image.
- : scale factor (stride) between the original image and the feature map.
- : quantized coordinates projected onto the feature map.
- and : floor (round down) and ceiling (round up) operations, respectively.
The size of the quantized ROI in the feature map is and .
The goal is to obtain a fixed-dimension output (e.g., ). To do this, we divide the ROI into a fixed-size grid. Each bin (where and ) covers a sub-window whose bounding coordinates undergo a second rounding:
Eq. 2: Calculation of vertical and horizontal boundaries for each ROI sub-window (bin).
Where:
- : desired fixed output dimensions.
- : height and width of the quantized ROI on the feature map.
- : indices of the sub-window in the output grid.
- : boundary coordinates of each sub-window on the feature map.
The Max Pooling operation is then applied to produce the output value in channel :
Eq. 3: Max Pooling operation applied to each ROI bin to generate the fixed output.
Where:
- : output pixel value in channel at grid position .
- : pixel value in the original feature map in channel at spatial coordinates .
- : mathematical operation that selects the maximum value within the sub-window boundaries.
🎯 When to use
- An inherent part of building classic two-stage models like Fast R-CNN.
- Extracting vector representations of specific regions of an image.
⚠️ Trade-offs and Pitfalls: As seen in the math above, the and operations introduce quantization errors (misalignment). The actual bounding box position and the grouped pixel positions lose sub-pixel alignment. For high-precision tasks (e.g., instance segmentation), roi-align replaces these roundings with sampling via bilinear interpolation.
Related: object-detection · fast-r-cnn