All problems
RoI Align Sample Points
Problem
Compute the sampling coordinates used by RoI Align. Each pooled cell is split into sampling_ratio x sampling_ratio sub-cells and a point is sampled at every sub-cell center.
For pooled cell (ph, pw) the point is y = y1 + (ph + (sy + 0.5) / sampling_ratio) * roi_h / pooled_size and x = x1 + (pw + (sx + 0.5) / sampling_ratio) * roi_w / pooled_size, where roi_h = y2 - y1 and roi_w = x2 - x1. Return the [y, x] points ordered by pooled cell row-major, then sy, then sx, rounded to 4 decimal places.
Test cases
case 1
in: [[0,0,4,4],2,2]
expected: [[0.5,0.5],[0.5,1.5],[1.5,0.5],[1.5,1.5],[0.5,2.5],[0.5,3.5],[1.5,2.5],[1.5,3.5],[2.5,0.5],[2.5,1.5],[3.5,0.5],[3.5,1.5],[2.5,2.5],[2.5,3.5],[3.5,2.5],[3.5,3.5]…
case 2
in: [[0,0,5,3],2,1]
expected: [[0.75,1.25],[0.75,3.75],[2.25,1.25],[2.25,3.75]]
case 3
in: [[1,2,4,6],1,2]
expected: [[3,1.75],[3,3.25],[5,1.75],[5,3.25]]
Starter codePython
def roi_align_points(roi, pooled_size, sampling_ratio):
# Your code here
pass3 test cases · run your code against them in the editor