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.padding_ mode_int0 = zeros, 1 = border.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 for bilinear/nearest).padding_ modeint0/1 for zeros/border).align_ cornersboolReturns
TensorImplPtrResampled tensor of shape (N, C, H_out, W_out).
Methods
2Backward pass: gradients w.r.t. input and grid.
Graph-mode backward: the kernel's adjoint written in ops — gathers, scatter-adds and the bilinear weights — so it can be differentiated again, in the input and the grid alike.