module onnxrt.ops_cpu.op_grid_sample#

Inheritance diagram of mlprodict.onnxrt.ops_cpu.op_grid_sample

Short summary#

module mlprodict.onnxrt.ops_cpu.op_grid_sample

Runtime operator.

source on GitHub



truncated documentation


GridSample ========== Given an input and a flow-field grid, computes the output using input values and pixel locations …



truncated documentation


Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …


Returns the list of modified parameters.


Returns the list of optional arguments.


Returns the list of optional arguments.


Returns all parameters in a dictionary.



truncated documentation




Runtime operator.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_grid_sample.GridSample(onnx_node, desc=None, **options)#

Bases: OpRun

Given an input and a flow-field grid, computes the output using input values and pixel locations from grid. Currently, only spatial (4-D) inputs are supported. For input with shape (N, C, H, W) and grid with shape (N, H_out, W_out, 2), the output will have shape (N, C, H_out, W_out). For each output location output[N, C, H_out, W_out], the size-2 vector grid[N, H_out, W_out] specifies input pixel locations x and y, which are used to interpolate the output value output[N, C, H_out, W_out].

The GridSample operator is often used in doing grid generator and sampler in the [Spatial Transformer Networks]( See also in [torch.nn.functional.grid_sample](


  • align_corners: If align_corners=1, the extrema (-1 and 1) are considered as referring to the center points of the input’s corner pixels. If align_corners=0, they are instead considered as referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic. Default value is namealigncornersi0typeINT (INT)

  • mode: Three interpolation modes: bilinear (default), nearest and bicubic. Default value is namemodesbilineartypeSTRING (STRING)

  • padding_mode: Support padding modes for outside grid values: zeros`(default), `border, reflection. zeros: use 0 for out-of-bound grid locations, border: use border values for out-of-bound grid locations, reflection: use values at locations reflected by the border for out-of-bound grid locations. If index 0 represents the margin pixel, the reflected value at index -1 will be the same as the value at index 1. For location far away from the border, it will keep being reflected until becoming in bound. If pixel location x = -3.5 reflects by border -1 and becomes x’ = 1.5, then reflects by border 1 and becomes x’’ = 0.5. Default value is namepaddingmodeszerostypeSTRING (STRING)


  • X (heterogeneous)T1: 4-D tensor of shape (N, C, H, W), where N is the batch size, C is the numbers of channels, H and W are the height and width of the input data.

  • grid (heterogeneous)T1: Input offset, 4-D tensor of shape (N, H_out, W_out, 2), where H_out and W_out are the height and width of grid and output, Grid specifies the sampling pixel locations normalized by the input spatial dimensions. Therefore, it should have most values in the range of [-1, 1]. If grid has values outside the range of [-1, 1], the corresponding outputs will be handled as defined by padding_mode.


  • Y (heterogeneous)T2: 4-D tensor of shape (N, C, H_out, W_out).

Type Constraints

  • T1 tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double), tensor(string), tensor(bool), tensor(complex64), tensor(complex128): Constrain input types to all tensor types.

  • T2 tensor(float16), tensor(float), tensor(double): Constrain output types to float tensors.


Onnx name: GridSample

This version of the operator has been available since version 16.

Runtime implementation: GridSample

__init__(onnx_node, desc=None, **options)#
_run(X, grid, attributes=None, verbose=0, fLOG=None)#

Should be overwritten.

source on GitHub