I need to use the grid_sample to do some work. In this situation, I already two images with different motions and their corresponding optical flow as follows:
And I use the following code to do this work:
import torch.nn as nn
import torch.nn.functional as F
img0 = imread('00000t0.png').astype(np.float32) #To load the image 1
img1 = imread('00000t1.png').astype(np.float32)#To load the image 2
img0 = np.array([img0])
img1 = np.array([img1])
flow = load_flo('00000.flo') #To load the flow field
flow = np.array([flow])
flow = torch.from_numpy(flow)
img0 = torch.from_numpy(img0)
result = F.grid_sample(img0, flow.clamp(-1,1))
The function can generate some results but which is totally not right. Is it right to use the grid_sample like this?