How to use grid_sample to do image deformation

Hi everyone, I wonder how to use grid_sample to deform an image? The deformation is not necessarily affine transform. I already have the deformed grid but I’m not sure if the deformed grid is the one I should put in grid_sample. For example, in the following case, I expect the strip between y=10~100 shift to the right because the x coordination of the deformed grid move along the positive direction. However, the image shifts to the left.

import torch
from skimage import data
from torch.nn.functional import grid_sample
import matplotlib.pyplot as plt

# read the image with OpenCV
image ='float32')
image = image[None]
img = torch.as_tensor(image)
angle = torch.deg2rad(45. * torch.ones(1))
x = torch.linspace(-1, 1, 512)
Y, X = torch.meshgrid(x, x)

X1 = X.clone()
X1[10:100] += 50/512
Y1 = Y.clone()
grid_deform = torch.stack([X1, Y1], dim=-1).unsqueeze(0)
img1 = grid_sample(img[None], grid_deform)[0,0]