Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for differentiable image resampling (grid sample).
Reads a 4-D input image at the (typically non-integer) positions specified by a sampling grid:
where is the chosen interpolation kernel and the grid stores
normalised coordinates in . For bilinear interpolation
the four neighbouring pixels around the unnormalised coordinate
,
(under align_corners_=true)
are combined with the standard bilinear weights; analogous neighbourhoods
of four (nearest) or sixteen (bicubic) pixels are used in the other modes.
Out-of-bounds samples are handled by padding_mode_: zeros returns
, border clamps the source coordinate, reflection reflects it
off the image boundary. The backward distributes grad_out back to both
the input pixels (through the interpolation weights) and the grid (through
the analytical derivative of the interpolation kernel).
Math
Coordinate unnormalisation:
(analogous formula for ).
References
Jaderberg et al., "Spatial Transformer Networks" (NeurIPS 2015).
Attributes
schema_v1OpSchema"grid_sample", AmpPolicy::Promote.mode_int0 = bilinear, 1 = nearest, 2 = bicubic.padding_mode_int0 = zeros, 1 = border, 2 = reflection.align_corners_boolinput_shape_Shape(N, C, H_in, W_in) for backward reconstruction.grid_shape_Shape(N, H_out, W_out, 2) for backward reconstruction.Static methods
1forward
→TensorImplPtrint forward(const int & input, const int & grid, int mode, int padding_mode, bool align_corners)Resample input at the positions specified by grid.
Parameters
inputTensorImplPtr(N, C, H_in, W_in).gridTensorImplPtr(N, H_out, W_out, 2) with normalised coordinates in .modeint0/1/2 for bilinear/nearest/bicubic).padding_modeint0/1/2 for zeros/border/reflection).align_cornersboolReturns
TensorImplPtrResampled tensor of shape (N, C, H_out, W_out).