This operation samples input X by using bilinear interpolation or
nearest interpolation based on flow field grid, which is usually
generated by :code:`affine_grid` . The grid of shape [N, H, W, 2]
is the concatenation of (x, y) coordinates with shape [N, H, W] each,
where x is indexing the 4th dimension (in width dimension) of input
data x and y is indexing the 3rd dimension (in height dimension),
finally results is the bilinear interpolation or nearest value of 4 nearest corner
points. The output tensor shape will be [N, C, H, W].
generated by :code:`affine_grid` . When the input X is 4-D Tensor,
the grid of shape [N, H, W, 2] is the concatenation of (x, y)
coordinates with shape [N, H, W] each, where x is indexing the 4th
dimension (in width dimension) of input data x and y is indexing
the 3rd dimension (in height dimension), finally results is the
bilinear interpolation or nearest value of 4 nearest corner
points. The output tensor shape will be [N, C, H, W]. When the input X
is 5-D Tensor, the grid of shape [N, D, H, W, 3] is the concatenation
of (x, y, z) coordinates with shape [N, D, H, W] each, where x is
indexing the 5th dimension (in width dimension) of input data x, y is
indexing the 4th dimension (in height dimension) and z is indexing the
3rd dimension (in depth dimension) finally results is the bilinear
interpolation or nearest value of 8 nearest cornerpoints. The output
tensor shape will be [N, C, D, H, W].
Step 1:
...
...
@@ -181,11 +190,13 @@ def grid_sample(x,
Args:
x(Tensor): The input tensor, which is a 4-d tensor with shape
[N, C, H, W], N is the batch size, C is the channel
number, H and W is the feature height and width.
[N, C, H, W] or a 5-d tensor with shape [N, C, D, H, W],
N is the batch size, C is the channel number,
D, H and W is the feature depth, height and width.
The data type is float32 or float64.
grid(Tensor): Input grid tensor of shape [N, grid_H, grid_W, 2]. The
data type is float32 or float64.
grid(Tensor): Input grid tensor, which is a 4-d tensor with shape [N, grid_H,
grid_W, 2] or a 5-d tensor with shape [N, grid_D, grid_H,
grid_W, 3]. The data type is float32 or float64.
mode(str, optional): The interpolation method which can be 'bilinear' or 'nearest'.
Default: 'bilinear'.
padding_mode(str, optional) The padding method used when source index
...
...
@@ -199,7 +210,8 @@ def grid_sample(x,
None by default.
Returns:
Tensor, The shape of output is [N, C, grid_H, grid_W] in which `grid_H` is the height of grid and `grid_W` is the width of grid. The data type is same as input tensor.
Tensor, The shape of output is [N, C, grid_H, grid_W] or [N, C, grid_D, grid_H, grid_W] in which `grid_D` is the depth of grid,
`grid_H` is the height of grid and `grid_W` is the width of grid. The data type is same as input tensor.