balbasty / torch-interpol

High-order spline interpolation in PyTorch
MIT License
62 stars 4 forks source link

align corners or not? #18

Open XiaLiPKU opened 2 weeks ago

XiaLiPKU commented 2 weeks ago

Thanks for your repo! Super helpful to my project.

One core issue for me is aligning it with torch.nn.functional.grid_sample. Is your implementation matched with align_corners=True or False?

Thanks in advance

balbasty commented 2 weeks ago

Hello!

In torch-interpol, coordinates are in voxels, and correspond to voxel centers: coordinate (0, 0) will map to the center of the first voxel, and coordinate (N-1, M-1) will map to the center of the last voxel in a tensor of shape [N, M].

It's different from grid_sample, where (-1, -1) maps to the first voxel and (1, 1) maps to the last corner (their center if align_corners=True, their external edge if align_corners=False).

So grid_pull's (0, 0) corresponds to grid_sample's (-1, -1) with align_corners=True, and grid_pull's (N-1, M-1) corresponds to grid_sample's (1, 1) with align_corners=True.

If you use our resize vs torch's interpolate, anchor="center" corresponds to align_corners=True, and anchor="edge" corresponds to align_corners=False.

Hope that helps!