:nosearch: .. _op_ai_onnx_Pad-11: Pad - version 11 ================ This page documents version **11** of operator **Pad**. See :doc:`Pad` for the latest version (since version 25). - **Domain**: ``ai.onnx`` - **Since version**: 11 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) 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): .. code-block:: text 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): .. code-block:: text 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): .. code-block:: text 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], ] **Inputs** - **data** (*T*): Input tensor. - **pads** (*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** (*T*): (Optional) A scalar value to be used if the mode chosen is ``constant`` (by default it is 0). **Outputs** - **output** (*T*): Tensor after padding. **Attributes** - **mode** (*string*): Supported modes: ``constant``(default), ``reflect``, ``edge`` **Type Constraints** - **T**: Constrain input and output to only numeric types. Allowed types: tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8). Differences with previous version (2) ------------------------------------- **SchemaDiff**: ``Pad`` (domain ``'ai.onnx'``) * old version: 2 * new version: 11 * breaking: **yes** **Breaking reasons:** * input 'pads' (added): at position 1; option=Single; type_str='tensor(int64)' * input 'constant_value' (added): at position 2; option=Single; type_str='T' * attribute 'value' (removed): type=FLOAT; required=False * attribute 'pads' (removed): type=INTS; required=True **Inputs:** * [BREAKING] added 'pads': at position 1; option=Single; type_str='tensor(int64)' * [BREAKING] added 'constant_value': at position 2; option=Single; type_str='T' **Attributes:** * [BREAKING] removed 'value': type=FLOAT; required=False * [BREAKING] removed 'pads': type=INTS; required=True **Type constraints:** * changed 'T': added types: ['tensor(int16)', 'tensor(int32)', 'tensor(int64)', 'tensor(int8)', 'tensor(uint16)', 'tensor(uint32)', 'tensor(uint64)', 'tensor(uint8)'] **Documentation:** * line similarity: 0.17 (+69/-9 lines) .. code-block:: diff --- Pad v2 +++ Pad v11 @@ -1,17 +1,77 @@ -Given `data` tensor, pads, mode, and value. -Example: +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) + +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 = [ + + data = + [ [1.0, 1.2], [2.3, 3.4], [4.5, 5.7], ] + pads = [0, 2, 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], - ], + + 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], + ] + +