Hey Sureerat, Not sure if you’ve already solved this, but I was just working on the exact same problem today. There is just one more step at the end that you could implement. The grid sample changes the orientation of the scan that you input so you use .permute() on your output tensor to reorient it.
I found to get the proper resampling I had to rearrange just the last three dimensions
>d1 = torch.linspace(-1, 1, self.shape[2])
> d2 = torch.linspace(-1, 1, self.shape[1])
> d3 = torch.linspace(-1, 1, self.shape[0])
> meshx, meshy, meshz = torch.meshgrid((d1, d2, d3))
> grid = torch.stack((meshx, meshy, meshz), 3)
> grid = grid.unsqueeze(0)  # add batch dim
> out = torch.nn.functional.grid_sample(x, grid)
> out = out.permute(0,1,4,3,2)