torch-问题函数--torch.nn.functional.grid_sample

时间:2024-03-22 16:57:55

torch.nn.functional.grid_sample(inputgridmode='bilinear'padding_mode='zeros')

我用于image warp的图像恢复

outpuy_{x,y} 的像素值与input_{x0,y0} 的像素值一致, 矩阵索引通过grid矩阵保存。 grid_{x,y}=(x0,y0)

In the spatial (4-D) case, for input with shape (N,C,Hin,Win)(N, C, H_\text{in}, W_\text{in})(N,C,Hin​,Win​) and grid with shape (N,Hout,Wout,2)(N, H_\text{out}, W_\text{out}, 2)(N,Hout​,Wout​,2), the output will have shape (N,C,Hout,Wout)(N, C, H_\text{out}, W_\text{out})(N,C,Hout​,Wout​).

input (N,C,H_in,W_in)

grid  (N ,H_out,W_out, 2) 

grid索引值(数据坐标)对应output索引值(数据坐标)

grid中数值对应input的索引值(数据坐标)

grid(u,v) = x,y

output(u,v)数值对应input(x,y)

示意图如下:

torch-问题函数--torch.nn.functional.grid_sample