The coordinate convention for the index in the grid sample is a bit surprising to me. Indeed, it seems to correspond to the standard tensor indexing coordinate but in reverse order.
Here is a code sample to observe what I am saying:
import torch a = torch.rand(1, 1, 4, 3) b = torch.nn.functional.grid_sample(a, torch.tensor([[[[1, -1]]]]).type(torch.FloatTensor), align_corners=True) #b corresponds to top right corner, i.e. j,i coordinates print(a[0, 0, 0, 2], b) c = torch.rand(1, 1, 4, 3, 2) d = torch.nn.functional.grid_sample(c, torch.tensor([[[[[1, 1, -1]]]]]).type(torch.FloatTensor), align_corners=True) #Again, here the convention is k, j, i print(c[0, 0, 0, 2, 1], d)
I was wondering if there were any reasoning behind this convention as it seems counter-intuitive to me.
Thank you for your help,