Details
ResourceFunction["GridSampleLayer"] is a lookup operator to a feature array using pixel coordinates. Inside a neural network this can be used to warp features between two views or to project a higher-order tensor by looking up pixel positions. This layer is often necessary in tasks where the coordinate array is a learning objective such as optical flow or when a feature array is a learning objective such as learnable parametric encodings for NERF or DeepSDF.
ResourceFunction["GridSampleLayer"] is typically used inside
NetChain,
NetGraph, etc.
The output of
ResourceFunction["GridSampleLayer"] is a
NetGraph with the following ports:
The possible values for mode of ResourceFunction["GridSampleLayer"] are:
The "Input" is a 2D feature array of dimensions {n,inWidth,inHeight}.
The "Index" is a 2D index array of dimensions {2,outWidth,outHeight}.
In ResourceFunction["GridSampleLayer"][n,{inWidth,inHeight},{outWidth,outHeight}], the arguments are defined as follows:
Bilinear interpolation is a sampling technique where the output at a point is the weighted average of the four nearest points on the grid. This sampling is the same as in
ResizeLayer with the "linear"
Resampling method, i.e. piecewise linear interpolation.
This GridSampleLayer is an implementation of torch.nn.functional.grid_sample (spatial 4-D) with this specific set of parameters:
-mode= 'bilinear'
-padding_mode= 'reflection'
-align_corners=False