TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

ROI Pooling

Computer Vision
Hard

Convert each rectangular region of a feature map into a fixed square grid with max pooling. Each region is [x1,y1,x2,y2][x_1,y_1,x_2,y_2][x1​,y1​,x2​,y2​] with half-open bounds, so it contains rows y1y_1y1​ through y2−1y_2-1y2​−1 and columns x1x_1x1​ through x2−1x_2-1x2​−1.

For output row iii, use:

hstart=y1+⌊iHRS⌋h_{\mathrm{start}}=y_1+\left\lfloor\frac{iH_R}{S}\right\rfloorhstart​=y1​+⌊SiHR​​⌋ hend=y1+⌊(i+1)HRS⌋h_{\mathrm{end}}=y_1+\left\lfloor\frac{(i+1)H_R}{S}\right\rfloorhend​=y1​+⌊S(i+1)HR​​⌋

For output column jjj, use:

wstart=x1+⌊jWRS⌋w_{\mathrm{start}}=x_1+\left\lfloor\frac{jW_R}{S}\right\rfloorwstart​=x1​+⌊SjWR​​⌋ wend=x1+⌊(j+1)WRS⌋w_{\mathrm{end}}=x_1+\left\lfloor\frac{(j+1)W_R}{S}\right\rfloorwend​=x1​+⌊S(j+1)WR​​⌋

Here, HR=y2−y1H_R=y_2-y_1HR​=y2​−y1​, WR=x2−x1W_R=x_2-x_1WR​=x2​−x1​, and SSS is output size. Expand an empty bin to one pixel, then take its maximum. Return one square two-dimensional list per region, preserving region order.

Loading visualization...

Examples

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]]]

Explanation: The full map splits into four two-by-two bins, and each output contains one bin maximum.

Input: feature_map = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], rois = [[0, 0, 2, 2], [2, 2, 4, 4]], output_size = 2

Output: [[[1, 2], [5, 6]], [[11, 12], [15, 16]]]

Hint 1

Use math.floor on each scaled bin boundary.

Hint 2

Collect values between each pair of half-open row and column boundaries, then take max.

Requirements

  • Divide every region into the requested number of rows and columns
  • Use the stated floor-based half-open bin boundaries
  • Expand empty bins to cover one pixel
  • Return one pooled grid per region in input order

Constraints

  • The feature map is a nonempty rectangular list
  • Region coordinates are integer, ordered, and within the feature map
  • Output size is a positive integer
Try Similar Problems
Anchor Box GenerationIou Bounding BoxNon Maximum SuppressionBilinear InterpolationMax Pooling 2d

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
PrevNext

ROI Pooling

Computer Vision
Hard

Convert each rectangular region of a feature map into a fixed square grid with max pooling. Each region is [x1,y1,x2,y2][x_1,y_1,x_2,y_2][x1​,y1​,x2​,y2​] with half-open bounds, so it contains rows y1y_1y1​ through y2−1y_2-1y2​−1 and columns x1x_1x1​ through x2−1x_2-1x2​−1.

For output row iii, use:

hstart=y1+⌊iHRS⌋h_{\mathrm{start}}=y_1+\left\lfloor\frac{iH_R}{S}\right\rfloorhstart​=y1​+⌊SiHR​​⌋ hend=y1+⌊(i+1)HRS⌋h_{\mathrm{end}}=y_1+\left\lfloor\frac{(i+1)H_R}{S}\right\rfloorhend​=y1​+⌊S(i+1)HR​​⌋

For output column jjj, use:

wstart=x1+⌊jWRS⌋w_{\mathrm{start}}=x_1+\left\lfloor\frac{jW_R}{S}\right\rfloorwstart​=x1​+⌊SjWR​​⌋ wend=x1+⌊(j+1)WRS⌋w_{\mathrm{end}}=x_1+\left\lfloor\frac{(j+1)W_R}{S}\right\rfloorwend​=x1​+⌊S(j+1)WR​​⌋

Here, HR=y2−y1H_R=y_2-y_1HR​=y2​−y1​, WR=x2−x1W_R=x_2-x_1WR​=x2​−x1​, and SSS is output size. Expand an empty bin to one pixel, then take its maximum. Return one square two-dimensional list per region, preserving region order.

Loading visualization...

Examples

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]]]

Explanation: The full map splits into four two-by-two bins, and each output contains one bin maximum.

Input: feature_map = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], rois = [[0, 0, 2, 2], [2, 2, 4, 4]], output_size = 2

Output: [[[1, 2], [5, 6]], [[11, 12], [15, 16]]]

Hint 1

Use math.floor on each scaled bin boundary.

Hint 2

Collect values between each pair of half-open row and column boundaries, then take max.

Requirements

  • Divide every region into the requested number of rows and columns
  • Use the stated floor-based half-open bin boundaries
  • Expand empty bins to cover one pixel
  • Return one pooled grid per region in input order

Constraints

  • The feature map is a nonempty rectangular list
  • Region coordinates are integer, ordered, and within the feature map
  • Output size is a positive integer
Try Similar Problems
Anchor Box GenerationIou Bounding BoxNon Maximum SuppressionBilinear InterpolationMax Pooling 2d

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: number

You must run your code first.