ref
com.microsoft - GridSample — Python Runtime for ONNX
onnx opset 16 adds this definition
Pit encountered when turning torch to onnx (1) - JoeyChen1219's Blog - CSDN Blog
Alignment in different align corner modes
First, the input x and y of the grid are normalized to the +-1 range. When align_corners=0 and 1, +-1 edge pixels are aligned to different positions of edge pixels.
Here, the input image has 4 pixels as an example to show different alignment methods.
The vertical arrow indicates the position corresponding to each pixel value, and the horizontal double-headed arrow indicates the spatial range occupied by each pixel.
It can be seen that when align_corners is 0, the image scaling factor scale is width/2, and when align_corners is 1, the image scaling factor scale is (width-1)/2. The center point corresponding to 0 after zooming is (width-1)/2.
Assuming that the real coordinates of the pixel are 0 to width-1, then the mapping from the grid coordinates to the input coordinates is out_pos*scale + (width-1)/2.