module onnxrt.ops_cpu.op_pad#

Inheritance diagram of mlprodict.onnxrt.ops_cpu.op_pad

Short summary#

module mlprodict.onnxrt.ops_cpu.op_pad

Runtime operator.

source on GitHub

Classes#

class

truncated documentation

Pad

Pad === Given a tensor containing the data to be padded (data), a tensor containing the number of start and end pad …

Functions#

function

truncated documentation

_pad_impl

onnx_pad

Implements numpy.pad based on ONNX signature.

Properties#

property

truncated documentation

args_default

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

args_default_modified

Returns the list of modified parameters.

args_mandatory

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

atts_value

Returns all parameters in a dictionary.

Methods#

method

truncated documentation

__init__

_infer_shapes

_infer_sizes

_infer_types

_run

Documentation#

Runtime operator.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_pad.Pad(onnx_node, desc=None, **options)#

Bases: OpRun

===

Given a tensor containing the data to be padded (data), a tensor containing the number of start and end pad values for axis (pads), (optionally) a mode, and (optionally) constant_value, a padded tensor (output) is generated.

The three supported modes are (similar to corresponding modes supported by numpy.pad):

  1. constant`(default) - pads with a given constant value as specified by `constant_value (which defaults to 0, empty string, or False)

  2. reflect - pads with the reflection of the vector mirrored on the first and last values of the vector along each axis

  3. edge - pads with the edge values of array

Example 1 (constant mode):

Insert 0 pads to the beginning of the second dimension.

data = [

[1.0, 1.2], [2.3, 3.4], [4.5, 5.7],

]

pads = [0, 2, 0, 0]

mode = ‘constant’

constant_value = 0.0

output = [

[0.0, 0.0, 1.0, 1.2], [0.0, 0.0, 2.3, 3.4], [0.0, 0.0, 4.5, 5.7],

]

Example 2 (reflect mode):

data = [

[1.0, 1.2], [2.3, 3.4], [4.5, 5.7],

]

pads = [0, 2, 0, 0]

mode = ‘reflect’

output = [

[1.0, 1.2, 1.0, 1.2], [2.3, 3.4, 2.3, 3.4], [4.5, 5.7, 4.5, 5.7],

]

Example 3 (edge mode):

data = [

[1.0, 1.2], [2.3, 3.4], [4.5, 5.7],

]

pads = [0, 2, 0, 0]

mode = ‘edge’

output = [

[1.0, 1.0, 1.0, 1.2], [2.3, 2.3, 2.3, 3.4], [4.5, 4.5, 4.5, 5.7],

]

Attributes

  • mode: Supported modes: constant`(default), `reflect, edge Default value is namemodesconstanttypeSTRING (STRING)

Inputs

Between 2 and 3 inputs.

  • data (heterogeneous)T: Input tensor.

  • pads (heterogeneous)tensor(int64): Tensor of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis. For 2D input tensor, it is the number of pixels. pads should be a 1D tensor of shape [2 * input_rank]. pads format should be: [x1_begin, x2_begin,…,x1_end, x2_end,…], where xi_begin is the number of pad values added at the beginning of axis i and xi_end, the number of pad values added at the end of axis i.

  • constant_value (optional, heterogeneous)T: (Optional) A scalar value to be used if the mode chosen is constant (by default it is 0, empty string or False).

Outputs

  • output (heterogeneous)T: Tensor after padding.

Type Constraints

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

Version

Onnx name: Pad

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

Runtime implementation: Pad

__init__(onnx_node, desc=None, **options)#
_infer_shapes(data, pads, constant_value=None)#

Should be overwritten.

source on GitHub

_infer_sizes(*args)#

Should be overwritten.

source on GitHub

_infer_types(data, pads, constant_value=None)#

Should be overwritten.

source on GitHub

_run(data, pads, constant_value=None, attributes=None, verbose=0, fLOG=None)#

Should be overwritten.

source on GitHub

mlprodict.onnxrt.ops_cpu.op_pad._pad_impl(data, raw_pads, mode, constant_values=0.0)#
mlprodict.onnxrt.ops_cpu.op_pad.onnx_pad(data, pads, constant_value=None, mode='constant')#

Implements numpy.pad based on ONNX signature.

Parameters:
  • data – data to pad

  • pads – tensor of integers indicating the number of padding elements to add or remove (if negative) at the beginning and end of each axis. For 2D input tensor, it is the number of pixels. pads should be a 1D tensor of shape [2 * input_rank]. pads format should be: [x1_begin, x2_begin,…,x1_end, x2_end,…], where xi_begin is the number of pad values added at the beginning of axis i and xi_end, the number of pad values added at the end of axis i.

  • constant_value – A scalar value to be used if the mode chosen is constant (by default it is 0, empty string or False).

  • mode – Supported modes: constant`(default), `reflect, edge

Returns:

tensor after padding

source on GitHub