How to reverse the operation of grid_sample?

If we get two images, target image tgt_img and source image src_img. And, we also know the grid
grid from source image to target image. Thus, we can use the F.grid_sample to generate target image from source image.

tgt_img = F.grid_sample(src_img, grid)

Is there any good idea to get the inv_grid that are from target image to source image. So that:

inv_grid = ?
src_img =  F.grid_sample(tgt_img, inv_grid)

I have tried to read the data in grid and generate a inv_grid, but I want to know if there any better and faster method.

1 Like

any guys can help me? :mask:

@huagl Have you got any solution for the inverse grid_sample?

Sorry, I haven’t checked the message for a long time. I still just read the data in grid and generate a inv_grid to solve this problem.
(PS. your name is the same as my senior’s who is in our lab. hh~)