Hi, @brinapingu,
The reason you get a poor warped image is that the function grid_sample() needs an input tensor in the range [0,1] rather than [0,255] (which is the default range of cv2). So you just have to normalize your img0. BTW, you have to be careful when warping an RGB image (cv2 reads as BRG order), img=img[:,:,::-1] may help assume the img is a numpy array with shape [H,W,3].
But I had the another question. Can anyone explain the functionality of the mask in the warp() function? In my understanding, the result of grid_sample  is exactly the warped result.
Thanks in advance.