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 X and a flow-field grid, computes the output Y using X 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 X and a flow-field grid, computes the output Y using X values and pixel locations from grid. Currently, only spatial (4-D) inputs are supported. For input X with shape (N, C, H, W) and grid with shape (N, H_out, W_out, 2), the output Y will have shape (N, C, H_out, W_out).

The tensor X contains values at centers of square pixels in a H by W 2-dimensional image. The tensor grid describes normalized positions where the output Y is to be computed using a specified interpolation method (the mode) and a padding mode (for grid positions falling outside the 2-dimensional image).

Elements in grid[N, H_out, W_out] are size-2 vectors specifying positions in the 2-dimensional space of X. They are used to interpolate output values of Y[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)T2: 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)T1: 4-D tensor of shape (N, C, H_out, W_out) of sampled values. For integer input types, intermediate values are computed as floating point and cast to integer at the end.

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 X and output Y types to all tensor types.

  • T2 tensor(float16), tensor(float), tensor(double): Constrain grid 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