@ptrblck sorry for late reply.
And I got the following error,
xv, yv = torch.meshgrid(torch.arange(im.size(2)), torch.arange(im.size(3)))
TypeError: meshgrid() takes 1 positional argument but 2 were given

And I find the answer,

xv, yv = torch.meshgrid(torch.arange(im.size(2)), torch.arange(im.size(3)))

should be,

xv, yv = torch.meshgrid([torch.arange(im.size(2)), torch.arange(im.size(3))])