# grid_sampler¶

step 1：

grid_x = 0.5 * (grid[:, :, :, 0] + 1) * (W - 1) grid_y = 0.5 * (grid[:, :, :, 1] + 1) * (H - 1)

step 2：

wn ------- y_n ------- en
|           |           |
|          d_n          |
|           |           |
x_w --d_w-- grid--d_e-- x_e
|           |           |
|          d_s          |
|           |           |
ws ------- y_s ------- wn

x_w = floor(x)              // west side x coord
x_e = x_w + 1               // east side x coord
y_n = floor(y)              // north side y coord
y_s = y_s + 1               // south side y coord
d_w = grid_x - x_w          // distance to west side
d_e = x_e - grid_x          // distance to east side
d_n = grid_y - y_n          // distance to north side
d_s = y_s - grid_y          // distance to south side
wn = X[:, :, y_n, x_w]      // north-west point value
en = X[:, :, y_n, x_e]      // north-east point value
ws = X[:, :, y_s, x_w]      // south-east point value
es = X[:, :, y_s, x_w]      // north-east point value

output = wn * d_e * d_s + en * d_w * d_s
+ ws * d_e * d_n + es * d_w * d_n

## 参数¶

• x (Variable): 输入张量，维度为 \([N, C, H, W]\) 的4-D Tensor，N为批尺寸，C是通道数，H是特征高度，W是特征宽度, 数据类型为float32或float64。
• grid (Variable): 输入网格数据张量，维度为 \([N, H, W, 2]\) 的4-D Tensor，N为批尺寸，C是通道数，H是特征高度，W是特征宽度, 数据类型为float32或float64。
• name (str，可选) – 具体用法请参见 Name ，一般无需设置。默认值：None。

## 返回¶

Variable(Tensor): 输入X基于输入网格的双线性插值计算结果，维度为 \([N, C, H, W]\) 的4-D Tensor