Pad - version 18#
This page documents version 18 of operator Pad. See Pad for the latest version (since version 25).
Domain:
ai.onnxSince version: 18
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):
constant``(default) - pads with a given constant value as specified by ``constant_value(which defaults to 0, empty string, or False)reflect- pads with the reflection of the vector mirrored on the first and last values of the vector along each axisedge- 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],
]
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.
padsshould be a 1D tensor of shape [2 * num_axes] wherenum_axesrefers to the number of elements in theaxesinput or the input rank ifaxesare not provided explicitly.padsformat should be: [x1_begin, x2_begin, …, x1_end, x2_end,…], where xi_begin is the number of pad values added at the beginning of axisaxes[i]and xi_end, the number of pad values added at the end of axisaxes[i].constant_value (T): (Optional) A scalar value to be used if the mode chosen is
constant(by default it is 0, empty string or False).axes (Tind): 1-D tensor of axes that
padsapply to. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data). Behavior is undefined if an axis is repeated. If not provided, all axes are assumed ([0, 1, ..., input_rank-1]).
Outputs
output (T): Tensor after padding.
Attributes
mode (string): Supported modes:
constant``(default), ``reflect,edge
Type Constraints
T: Constrain input and output types to all tensor types. Allowed types: tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).
Tind: Constrain indices to integer types Allowed types: tensor(int32), tensor(int64).
Examples#
test_cc_shape_inference_pad_canny_average
Node:
Pad(X, pads) -> (padded)
Attributes:
mode = "reflect"
Inputs:
X: shape=(2, 1, 5, 7), dtype=float32
[[[[ 1., 2., 3., ..., 5., 6., 7.],
[ 8., 9., 10., ..., 12., 13., 14.],
[15., 16., 17., ..., 19., 20., 21.],
[22., 23., 24., ..., 26., 27., 28.],
[29., 30., 31., ..., 33., 34., 35.]]],
[[[36., 37., 38., ..., 40., 41., 42.],
[43., 44., 45., ..., 47., 48., 49.],
[50., 51., 52., ..., 54., 55., 56.],
[57., 58., 59., ..., 61., 62., 63.],
[64., 65., 66., ..., 68., 69., 70.]]]]
Outputs:
padded: shape=(2, 1, 5, 7), dtype=float32
[[[[-16., -14., -14., ..., -14., -14., -12.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ 12., 14., 14., ..., 14., 14., 16.]]],
[[[-16., -14., -14., ..., -14., -14., -12.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ -2., 0., 0., ..., 0., 0., 2.],
[ 12., 14., 14., ..., 14., 14., 16.]]]]
Differences with previous version (13)#
SchemaDiff: Pad (domain 'ai.onnx')
old version: 13
new version: 18
breaking: yes
Breaking reasons:
input ‘axes’ (added): at position 3; option=Single; type_str=’Tind’
Inputs:
[BREAKING] added ‘axes’: at position 3; option=Single; type_str=’Tind’
Type constraints:
added ‘Tind’: added types: [‘tensor(int32)’, ‘tensor(int64)’]
Documentation:
line similarity: 0.42 (+44/-45 lines)
--- Pad v13
+++ Pad v18
@@ -12,66 +12,65 @@
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],
- ]
+Insert 0 pads to the beginning of the second dimension.
- pads = [0, 2, 0, 0]
+```
+data = [
+ [1.0, 1.2],
+ [2.3, 3.4],
+ [4.5, 5.7],
+]
- mode = 'constant'
+pads = [0, 2, 0, 0]
- constant_value = 0.0
+mode = 'constant'
- 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],
- ]
+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]
+```
+data = [
+ [1.0, 1.2],
+ [2.3, 3.4],
+ [4.5, 5.7],
+]
- mode = 'reflect'
+pads = [0, 2, 0, 0]
- 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],
- ]
+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]
+```
+data = [
+ [1.0, 1.2],
+ [2.3, 3.4],
+ [4.5, 5.7],
+]
- mode = 'edge'
+pads = [0, 2, 0, 0]
- 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],
- ]
+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],
+]
+```