AveragePool#
AveragePool  11#
Version
name: AveragePool (GitHub)
domain: main
since_version: 11
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 11.
Summary
AveragePool consumes an input tensor X and applies average pooling across the tensor according to kernel sizes, stride sizes, and pad lengths. average pooling consisting of computing the average on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor Y for further processing. The output spatial shape will be following:
output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
or#
output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
if ceil_mode is enabled
* pad_shape[i] is sum of pads along axis i
auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])
SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
And pad shape will be following if SAME_UPPER or SAME_LOWER:
pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i]
The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).
Attributes
auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that output_shape[i] = ceil(input_shape[i] / strides[i]) for each axis i. The padding is split between the two sides equally or almost equally (depending on whether it is even or odd). In case the padding is an odd number, the extra padding is added at the end for SAME_UPPER and at the beginning for SAME_LOWER. Default value is
'NOTSET'
.ceil_mode: Whether to use ceil or floor (default) to compute the output shape. Default value is
0
.count_include_pad: Whether include pad pixels when calculating values for the edges. Default is 0, doesn’t count include pad. Default value is
0
.kernel_shape (required): The size of the kernel along each axis.
pads: Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. pads format should be as follow [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
strides: Stride along each spatial axis. If not present, the stride defaults to 1 along each spatial axis.
Inputs
X (heterogeneous)  T: Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 … Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE …].
Outputs
Y (heterogeneous)  T: Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.
Examples
_averagepool_2d_precomputed_pads
"""
input_shape: [1, 1, 5, 5]
output_shape: [1, 1, 5, 5]
pad_shape: [4, 4] > [2, 2, 2, 2] by axis
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[5, 5],
pads=[2, 2, 2, 2],
)
x = np.array(
[
[
[
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25],
]
]
]
).astype(np.float32)
y = np.array(
[
[
[
[7, 7.5, 8, 8.5, 9],
[9.5, 10, 10.5, 11, 11.5],
[12, 12.5, 13, 13.5, 14],
[14.5, 15, 15.5, 16, 16.5],
[17, 17.5, 18, 18.5, 19],
]
]
]
).astype(np.float32)
expect(
node, inputs=[x], outputs=[y], name="test_averagepool_2d_precomputed_pads"
)
_averagepool_2d_precomputed_pads_count_include_pad
"""
input_shape: [1, 1, 5, 5]
output_shape: [1, 1, 5, 5]
pad_shape: [4, 4] > [2, 2, 2, 2] by axis
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[5, 5],
pads=[2, 2, 2, 2],
count_include_pad=1,
)
x = np.array(
[
[
[
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25],
]
]
]
).astype(np.float32)
y = np.array(
[
[
[
[2.5200, 3.6000, 4.8000, 4.0800, 3.2400],
[4.5600, 6.4000, 8.4000, 7.0400, 5.5200],
[7.2000, 10.0000, 13.0000, 10.8000, 8.4000],
[6.9600, 9.6000, 12.4000, 10.2400, 7.9200],
[6.1200, 8.4000, 10.8000, 8.8800, 6.8400],
]
]
]
).astype(np.float32)
expect(
node,
inputs=[x],
outputs=[y],
name="test_averagepool_2d_precomputed_pads_count_include_pad",
)
_averagepool_2d_precomputed_strides
"""
input_shape: [1, 1, 5, 5]
output_shape: [1, 1, 2, 2]
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[2, 2],
strides=[2, 2],
)
x = np.array(
[
[
[
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25],
]
]
]
).astype(np.float32)
y = np.array([[[[4, 6], [14, 16]]]]).astype(np.float32)
expect(
node,
inputs=[x],
outputs=[y],
name="test_averagepool_2d_precomputed_strides",
)
_averagepool_2d_precomputed_same_upper
"""
input_shape: [1, 1, 5, 5]
output_shape: [1, 1, 3, 3]
pad_shape: [2, 2] > [1, 1, 1, 1] by axis
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[3, 3],
strides=[2, 2],
auto_pad="SAME_UPPER",
)
x = np.array(
[
[
[
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25],
]
]
]
).astype(np.float32)
y = np.array([[[[4, 5.5, 7], [11.5, 13, 14.5], [19, 20.5, 22]]]]).astype(
np.float32
)
expect(
node,
inputs=[x],
outputs=[y],
name="test_averagepool_2d_precomputed_same_upper",
)
_averagepool_1d_default
"""
input_shape: [1, 3, 32]
output_shape: [1, 3, 31]
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[2],
)
x = np.random.randn(1, 3, 32).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = [2]
strides = [1]
out_shape = get_output_shape("VALID", x_shape[2:], kernel_shape, strides)
padded = x
y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0], "AVG")
expect(node, inputs=[x], outputs=[y], name="test_averagepool_1d_default")
_averagepool_2d_default
"""
input_shape: [1, 3, 32, 32]
output_shape: [1, 3, 31, 31]
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[2, 2],
)
x = np.random.randn(1, 3, 32, 32).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = (2, 2)
strides = (1, 1)
out_shape = get_output_shape("VALID", x_shape[2:], kernel_shape, strides)
padded = x
y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), "AVG")
expect(node, inputs=[x], outputs=[y], name="test_averagepool_2d_default")
_averagepool_3d_default
"""
input_shape: [1, 3, 32, 32, 32]
output_shape: [1, 3, 31, 31, 31]
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[2, 2, 2],
)
x = np.random.randn(1, 3, 32, 32, 32).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = [2, 2, 2]
strides = [1, 1, 1]
out_shape = get_output_shape("VALID", x_shape[2:], kernel_shape, strides)
padded = x
y = pool(padded, x_shape, kernel_shape, strides, out_shape, [0, 0, 0], "AVG")
expect(node, inputs=[x], outputs=[y], name="test_averagepool_3d_default")
_averagepool_2d_same_upper
"""
input_shape: [1, 3, 32, 32]
output_shape: [1, 3, 32, 32]
pad_shape: [1, 1] > [0, 1, 0, 1] by axis
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[2, 2],
auto_pad="SAME_UPPER",
)
x = np.random.randn(1, 3, 32, 32).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = (2, 2)
strides = (1, 1)
out_shape = get_output_shape("SAME_UPPER", x_shape[2:], kernel_shape, strides)
pad_shape = get_pad_shape(
"SAME_UPPER", x_shape[2:], kernel_shape, strides, out_shape
)
pad_top = pad_shape[0] // 2
pad_bottom = pad_shape[0]  pad_top
pad_left = pad_shape[1] // 2
pad_right = pad_shape[1]  pad_left
padded = np.pad(
x,
((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)),
mode="constant",
constant_values=np.nan,
)
y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, "AVG")
expect(node, inputs=[x], outputs=[y], name="test_averagepool_2d_same_upper")
_averagepool_2d_same_lower
"""
input_shape: [1, 3, 32, 32]
output_shape: [1, 3, 32, 32]
pad_shape: [1, 1] > [1, 0, 1, 0] by axis
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[2, 2],
auto_pad="SAME_LOWER",
)
x = np.random.randn(1, 3, 32, 32).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = (2, 2)
strides = (1, 1)
out_shape = get_output_shape("SAME_LOWER", x_shape[2:], kernel_shape, strides)
pad_shape = get_pad_shape(
"SAME_LOWER", x_shape[2:], kernel_shape, strides, out_shape
)
pad_bottom = pad_shape[0] // 2
pad_top = pad_shape[0]  pad_bottom
pad_right = pad_shape[1] // 2
pad_left = pad_shape[1]  pad_right
padded = np.pad(
x,
((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)),
mode="constant",
constant_values=np.nan,
)
y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, "AVG")
expect(node, inputs=[x], outputs=[y], name="test_averagepool_2d_same_lower")
_averagepool_2d_pads
"""
input_shape: [1, 3, 28, 28]
output_shape: [1, 3, 30, 30]
pad_shape: [4, 4] > [2, 2, 2, 2] by axis
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[3, 3],
pads=[2, 2, 2, 2],
)
x = np.random.randn(1, 3, 28, 28).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = (3, 3)
strides = (1, 1)
pad_bottom = 2
pad_top = 2
pad_right = 2
pad_left = 2
pad_shape = [pad_top + pad_bottom, pad_left + pad_right]
out_shape = get_output_shape(
"VALID", np.add(x_shape[2:], pad_shape), kernel_shape, strides
)
padded = np.pad(
x,
((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)),
mode="constant",
constant_values=np.nan,
)
y = pool(padded, x_shape, kernel_shape, strides, out_shape, pad_shape, "AVG")
expect(node, inputs=[x], outputs=[y], name="test_averagepool_2d_pads")
_averagepool_2d_pads_count_include_pad
"""
input_shape: [1, 3, 28, 28]
output_shape: [1, 3, 30, 30]
pad_shape: [4, 4] > [2, 2, 2, 2] by axis
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[3, 3],
pads=[2, 2, 2, 2],
count_include_pad=1,
)
x = np.random.randn(1, 3, 28, 28).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = (3, 3)
strides = (1, 1)
pad_bottom = 2
pad_top = 2
pad_right = 2
pad_left = 2
pad_shape = [pad_top + pad_bottom, pad_left + pad_right]
out_shape = get_output_shape(
"VALID", np.add(x_shape[2:], pad_shape), kernel_shape, strides
)
padded = np.pad(
x,
((0, 0), (0, 0), (pad_top, pad_bottom), (pad_left, pad_right)),
mode="constant",
constant_values=0,
)
y = pool(
padded,
x_shape,
kernel_shape,
strides,
out_shape,
pad_shape,
"AVG",
count_include_pad=1,
)
expect(
node,
inputs=[x],
outputs=[y],
name="test_averagepool_2d_pads_count_include_pad",
)
_averagepool_2d_strides
"""
input_shape: [1, 3, 32, 32]
output_shape: [1, 3, 10, 10]
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[5, 5],
strides=[3, 3],
)
x = np.random.randn(1, 3, 32, 32).astype(np.float32)
x_shape = np.shape(x)
kernel_shape = (5, 5)
strides = (3, 3)
out_shape = get_output_shape("VALID", x_shape[2:], kernel_shape, strides)
padded = x
y = pool(padded, x_shape, kernel_shape, strides, out_shape, (0, 0), "AVG")
expect(node, inputs=[x], outputs=[y], name="test_averagepool_2d_strides")
_averagepool_2d_ceil
"""
input_shape: [1, 1, 4, 4]
output_shape: [1, 1, 2, 2]
"""
node = onnx.helper.make_node(
"AveragePool",
inputs=["x"],
outputs=["y"],
kernel_shape=[3, 3],
strides=[2, 2],
ceil_mode=True,
)
x = np.array(
[
[
[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16],
]
]
]
).astype(np.float32)
y = np.array([[[[6, 7.5], [12, 13.5]]]]).astype(np.float32)
expect(node, inputs=[x], outputs=[y], name="test_averagepool_2d_ceil")
Differences
0  0  AveragePool consumes an input tensor X and applies average pooling across  AveragePool consumes an input tensor X and applies average pooling across 
1  1  the tensor according to kernel sizes, stride sizes, and pad lengths.  the tensor according to kernel sizes, stride sizes, and pad lengths. 
2  2  average pooling consisting of computing the average on all values of a  average pooling consisting of computing the average on all values of a 
3  3  subset of the input tensor according to the kernel size and downsampling the  subset of the input tensor according to the kernel size and downsampling the 
4  4  data into the output tensor Y for further processing. The output spatial shape will be following:  data into the output tensor Y for further processing. The output spatial shape will be following: 
5  5  ::  :: 
6  6 


7  7  output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)  output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) 
8  8 


9  9  or  or 
10  10  ::  :: 
11  11 


12  12  output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)  output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) 
13  13 


14  14  if ceil_mode is enabled  if ceil_mode is enabled 
15  15 


16  16  ::  :: 
17  17 


18  18  * pad_shape[i] is sum of pads along axis i  * pad_shape[i] is sum of pads along axis i 
19  19 


20  20  auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:  auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: 
21  21  ::  :: 
22  22 


23  23  VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])  VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) 
24  24  SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])  SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) 
25  25 


26  26  And pad shape will be following if SAME_UPPER or SAME_LOWER:  And pad shape will be following if SAME_UPPER or SAME_LOWER: 
27  27  ::  :: 
28  28 


29  29  pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i]  pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i] 
30  30 


31  31  The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).  The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). 
32  32 


33  33  **Attributes**  **Attributes** 
34  34 


35  35  * **auto_pad**:  * **auto_pad**: 
36  36  auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.  auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. 
37  37  Where default value is NOTSET, which means explicit padding is used.  Where default value is NOTSET, which means explicit padding is used. 
38  38  SAME_UPPER or SAME_LOWER mean pad the input so that the output 

39  spatial size match the input.In case of odd number add the extra  
39  = ceil(input_shape[i] / strides[i]) for each axis i. The padding  
40  is split between the two sides equally or almost equally (depending  
41  on whether it is even or odd). In case the padding is an odd number,  
40  42  padding at the end for SAME_UPPER and at the beginning for 

41  43  SAME_LOWER. VALID mean no padding. Default value is 'NOTSET'. 

42  44  * **ceil_mode**:  * **ceil_mode**: 
43  45  Whether to use ceil or floor (default) to compute the output shape. Default value is 0.  Whether to use ceil or floor (default) to compute the output shape. Default value is 0. 
44  46  * **count_include_pad**:  * **count_include_pad**: 
45  47  Whether include pad pixels when calculating values for the edges.  Whether include pad pixels when calculating values for the edges. 
46  48  Default is 0, doesn't count include pad. Default value is 0.  Default is 0, doesn't count include pad. Default value is 0. 
47  49  * **kernel_shape** (required):  * **kernel_shape** (required): 
48  50  The size of the kernel along each axis.  The size of the kernel along each axis. 
49  51  * **pads**:  * **pads**: 
50  52  Padding for the beginning and ending along each spatial axis, it can  Padding for the beginning and ending along each spatial axis, it can 
51  53  take any value greater than or equal to 0. The value represent the  take any value greater than or equal to 0. The value represent the 
52  54  number of pixels added to the beginning and end part of the  number of pixels added to the beginning and end part of the 
53  55  corresponding axis. pads format should be as follow [x1_begin,  corresponding axis. pads format should be as follow [x1_begin, 
54  56  x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels  x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels 
55  57  added at the beginning of axis i and xi_end, the number of pixels  added at the beginning of axis i and xi_end, the number of pixels 
56  58  added at the end of axis i. This attribute cannot be used  added at the end of axis i. This attribute cannot be used 
57  59  simultaneously with auto_pad attribute. If not present, the padding  simultaneously with auto_pad attribute. If not present, the padding 
58  60  defaults to 0 along start and end of each spatial axis.  defaults to 0 along start and end of each spatial axis. 
59  61  * **strides**:  * **strides**: 
60  62  Stride along each spatial axis. 

63  to 1 along each spatial axis.  
61  64 


62  65  **Inputs**  **Inputs** 
63  66 


64  67  * **X** (heterogeneous)  **T**:  * **X** (heterogeneous)  **T**: 
65  68  Input data tensor from the previous operator; dimensions for image  Input data tensor from the previous operator; dimensions for image 
66  69  case are (N x C x H x W), where N is the batch size, C is the number  case are (N x C x H x W), where N is the batch size, C is the number 
67  70  of channels, and H and W are the height and the width of the data.  of channels, and H and W are the height and the width of the data. 
68  71  For non image case, the dimensions are in the form of (N x C x D1 x  For non image case, the dimensions are in the form of (N x C x D1 x 
69  72  D2 ... Dn), where N is the batch size. Optionally, if dimension  D2 ... Dn), where N is the batch size. Optionally, if dimension 
70  73  denotation is in effect, the operation expects the input data tensor  denotation is in effect, the operation expects the input data tensor 
71  74  to arrive with the dimension denotation of [DATA_BATCH,  to arrive with the dimension denotation of [DATA_BATCH, 
72  75  DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].  DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...]. 
73  76 


74  77  **Outputs**  **Outputs** 
75  78 


76  79  * **Y** (heterogeneous)  **T**:  * **Y** (heterogeneous)  **T**: 
77  80  Output data tensor from average or max pooling across the input  Output data tensor from average or max pooling across the input 
78  81  tensor. Dimensions will vary based on various kernel, stride, and  tensor. Dimensions will vary based on various kernel, stride, and 
79  82  pad sizes. Floor value of the dimension is used  pad sizes. Floor value of the dimension is used 
80  83 


81  84  **Type Constraints**  **Type Constraints** 
82  85 


83  86  * **T** in (  * **T** in ( 
84  87  tensor(double),  tensor(double), 
85  88  tensor(float),  tensor(float), 
86  89  tensor(float16)  tensor(float16) 
87  90  ):  ): 
88  91  Constrain input and output types to float tensors.  Constrain input and output types to float tensors. 
AveragePool  10#
Version
name: AveragePool (GitHub)
domain: main
since_version: 10
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 10.
Summary
AveragePool consumes an input tensor X and applies average pooling across the tensor according to kernel sizes, stride sizes, and pad lengths. average pooling consisting of computing the average on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor Y for further processing. The output spatial shape will be following:
output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
or#
output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
if ceil_mode is enabled
* pad_shape[i] is sum of pads along axis i
auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])
SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
And pad shape will be following if SAME_UPPER or SAME_LOWER:
pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i]
The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).
Attributes
auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding. Default value is
'NOTSET'
.ceil_mode: Whether to use ceil or floor (default) to compute the output shape. Default value is
0
.count_include_pad: Whether include pad pixels when calculating values for the edges. Default is 0, doesn’t count include pad. Default value is
0
.kernel_shape (required): The size of the kernel along each axis.
pads: Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. pads format should be as follow [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
strides: Stride along each spatial axis.
Inputs
X (heterogeneous)  T: Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 … Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE …].
Outputs
Y (heterogeneous)  T: Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.
Differences
0  0  AveragePool consumes an input tensor X and applies average pooling across  AveragePool consumes an input tensor X and applies average pooling across 
1  1  the tensor according to kernel sizes, stride sizes, and pad lengths.  the tensor according to kernel sizes, stride sizes, and pad lengths. 
2  2  average pooling consisting of computing the average on all values of a  average pooling consisting of computing the average on all values of a 
3  3  subset of the input tensor according to the kernel size and downsampling the  subset of the input tensor according to the kernel size and downsampling the 
4  4  data into the output tensor Y for further processing. The output spatial shape will be following:  data into the output tensor Y for further processing. The output spatial shape will be following: 
5  5  ::  :: 
6  6 


7  7  output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)  output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) 
8  8 


9  or  
10  ::  
11 
 
12  output_spatial_shape[i] = ceil((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)  
13 
 
14  if ceil_mode is enabled  
15 
 
16  ::  
17 
 
9  18  * pad_shape[i] is sum of pads along axis i  * pad_shape[i] is sum of pads along axis i 
10  19 


11  20  auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:  auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: 
12  21  ::  :: 
13  22 


14  23  VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])  VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) 
15  24  SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])  SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) 
16  25 


17  26  And pad shape will be following if SAME_UPPER or SAME_LOWER:  And pad shape will be following if SAME_UPPER or SAME_LOWER: 
18  27  ::  :: 
19  28 


20  29  pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i]  pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i] 
21  30 


22  31  The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).  The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero). 
23  32 


24  33  **Attributes**  **Attributes** 
25  34 


26  35  * **auto_pad**:  * **auto_pad**: 
27  36  auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.  auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. 
28  37  Where default value is NOTSET, which means explicit padding is used.  Where default value is NOTSET, which means explicit padding is used. 
29  38  SAME_UPPER or SAME_LOWER mean pad the input so that the output  SAME_UPPER or SAME_LOWER mean pad the input so that the output 
30  39  spatial size match the input.In case of odd number add the extra  spatial size match the input.In case of odd number add the extra 
31  40  padding at the end for SAME_UPPER and at the beginning for  padding at the end for SAME_UPPER and at the beginning for 
32  41  SAME_LOWER. VALID mean no padding. Default value is 'NOTSET'.  SAME_LOWER. VALID mean no padding. Default value is 'NOTSET'. 
42  * **ceil_mode**:  
43  Whether to use ceil or floor (default) to compute the output shape. Default value is 0.  
33  44  * **count_include_pad**:  * **count_include_pad**: 
34  45  Whether include pad pixels when calculating values for the edges.  Whether include pad pixels when calculating values for the edges. 
35  46  Default is 0, doesn't count include pad. Default value is 0.  Default is 0, doesn't count include pad. Default value is 0. 
36  47  * **kernel_shape** (required):  * **kernel_shape** (required): 
37  48  The size of the kernel along each axis.  The size of the kernel along each axis. 
38  49  * **pads**:  * **pads**: 
39  50  Padding for the beginning and ending along each spatial axis, it can  Padding for the beginning and ending along each spatial axis, it can 
40  51  take any value greater than or equal to 0. The value represent the  take any value greater than or equal to 0. The value represent the 
41  52  number of pixels added to the beginning and end part of the  number of pixels added to the beginning and end part of the 
42  53  corresponding axis. pads format should be as follow [x1_begin,  corresponding axis. pads format should be as follow [x1_begin, 
43  54  x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels  x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels 
44  55  added at the beginning of axis i and xi_end, the number of pixels  added at the beginning of axis i and xi_end, the number of pixels 
45  56  added at the end of axis i. This attribute cannot be used  added at the end of axis i. This attribute cannot be used 
46  57  simultaneously with auto_pad attribute. If not present, the padding  simultaneously with auto_pad attribute. If not present, the padding 
47  58  defaults to 0 along start and end of each spatial axis.  defaults to 0 along start and end of each spatial axis. 
48  59  * **strides**:  * **strides**: 
49  60  Stride along each spatial axis.  Stride along each spatial axis. 
50  61 


51  62  **Inputs**  **Inputs** 
52  63 


53  64  * **X** (heterogeneous)  **T**:  * **X** (heterogeneous)  **T**: 
54  65  Input data tensor from the previous operator; dimensions for image  Input data tensor from the previous operator; dimensions for image 
55  66  case are (N x C x H x W), where N is the batch size, C is the number  case are (N x C x H x W), where N is the batch size, C is the number 
56  67  of channels, and H and W are the height and the width of the data.  of channels, and H and W are the height and the width of the data. 
57  68  For non image case, the dimensions are in the form of (N x C x D1 x  For non image case, the dimensions are in the form of (N x C x D1 x 
58  69  D2 ... Dn), where N is the batch size. Optionally, if dimension  D2 ... Dn), where N is the batch size. Optionally, if dimension 
59  70  denotation is in effect, the operation expects the input data tensor  denotation is in effect, the operation expects the input data tensor 
60  71  to arrive with the dimension denotation of [DATA_BATCH,  to arrive with the dimension denotation of [DATA_BATCH, 
61  72  DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].  DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...]. 
62  73 


63  74  **Outputs**  **Outputs** 
64  75 


65  76  * **Y** (heterogeneous)  **T**:  * **Y** (heterogeneous)  **T**: 
66  77  Output data tensor from average or max pooling across the input  Output data tensor from average or max pooling across the input 
67  78  tensor. Dimensions will vary based on various kernel, stride, and  tensor. Dimensions will vary based on various kernel, stride, and 
68  79  pad sizes. Floor value of the dimension is used  pad sizes. Floor value of the dimension is used 
69  80 


70  81  **Type Constraints**  **Type Constraints** 
71  82 


72  83  * **T** in (  * **T** in ( 
73  84  tensor(double),  tensor(double), 
74  85  tensor(float),  tensor(float), 
75  86  tensor(float16)  tensor(float16) 
76  87  ):  ): 
77  88  Constrain input and output types to float tensors.  Constrain input and output types to float tensors. 
AveragePool  7#
Version
name: AveragePool (GitHub)
domain: main
since_version: 7
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 7.
Summary
AveragePool consumes an input tensor X and applies average pooling across the tensor according to kernel sizes, stride sizes, and pad lengths. average pooling consisting of computing the average on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor Y for further processing. The output spatial shape will be following:
output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
* pad_shape[i] is sum of pads along axis i
auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])
SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
And pad shape will be following if SAME_UPPER or SAME_LOWER:
pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i]
The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).
Attributes
auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding. Default value is
'NOTSET'
.count_include_pad: Whether include pad pixels when calculating values for the edges. Default is 0, doesn’t count include pad. Default value is
0
.kernel_shape (required): The size of the kernel along each axis.
pads: Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. pads format should be as follow [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
strides: Stride along each spatial axis.
Inputs
X (heterogeneous)  T: Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 … Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE …].
Outputs
Y (heterogeneous)  T: Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.
Differences
0  0  AveragePool consumes an input tensor X and applies average pooling across  AveragePool consumes an input tensor X and applies average pooling across 
1  1  the tensor according to kernel sizes, stride sizes, and pad lengths.  the tensor according to kernel sizes, stride sizes, and pad lengths. 
2  2  average pooling consisting of computing the average on all values of a  average pooling consisting of computing the average on all values of a 
3  3  subset of the input tensor according to the kernel size and downsampling the  subset of the input tensor according to the kernel size and downsampling the 
4  4  data into the output tensor Y for further processing. The output spatial shape will be following:  data into the output tensor Y for further processing. The output spatial shape will be following: 
5  5  ::  :: 
6  6 


7  7  output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)  output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1) 
8  8 


9  9  * pad_shape[i] is sum of pads along axis i  * pad_shape[i] is sum of pads along axis i 
10  10 


11  11  auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:  auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following: 
12  12  ::  :: 
13  13 


14  14  VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])  VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i]) 
15  15  SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])  SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i]) 
16  16 


17  17  And pad shape will be following if SAME_UPPER or SAME_LOWER:  And pad shape will be following if SAME_UPPER or SAME_LOWER: 
18  18  ::  :: 
19  19 


20  20  pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i]  pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i] 
21  21 


22  22  The output of each pooling window is divided by the number of elements exclude pad. 

23  23 


24  24  **Attributes**  **Attributes** 
25  25 


26  26  * **auto_pad**:  * **auto_pad**: 
27  27  auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.  auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. 
28  28  Where default value is NOTSET, which means explicit padding is used.  Where default value is NOTSET, which means explicit padding is used. 
29  29  SAME_UPPER or SAME_LOWER mean pad the input so that the output  SAME_UPPER or SAME_LOWER mean pad the input so that the output 
30  30  spatial size match the input.In case of odd number add the extra  spatial size match the input.In case of odd number add the extra 
31  31  padding at the end for SAME_UPPER and at the beginning for  padding at the end for SAME_UPPER and at the beginning for 
32  32  SAME_LOWER. VALID mean no padding. Default value is 'NOTSET'.  SAME_LOWER. VALID mean no padding. Default value is 'NOTSET'. 
33  * **count_include_pad**:  
34  Whether include pad pixels when calculating values for the edges.  
35  Default is 0, doesn't count include pad. Default value is 0.  
33  36  * **kernel_shape** (required):  * **kernel_shape** (required): 
34  37  The size of the kernel along each axis.  The size of the kernel along each axis. 
35  38  * **pads**:  * **pads**: 
36  39  Padding for the beginning and ending along each spatial axis, it can  Padding for the beginning and ending along each spatial axis, it can 
37  40  take any value greater than or equal to 0. The value represent the  take any value greater than or equal to 0. The value represent the 
38  41  number of pixels added to the beginning and end part of the  number of pixels added to the beginning and end part of the 
39  42  corresponding axis. pads format should be as follow [x1_begin,  corresponding axis. pads format should be as follow [x1_begin, 
40  43  x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels  x2_begin...x1_end, x2_end,...], where xi_begin the number of pixels 
41  44  added at the beginning of axis i and xi_end, the number of pixels  added at the beginning of axis i and xi_end, the number of pixels 
42  45  added at the end of axis i. This attribute cannot be used  added at the end of axis i. This attribute cannot be used 
43  46  simultaneously with auto_pad attribute. If not present, the padding  simultaneously with auto_pad attribute. If not present, the padding 
44  47  defaults to 0 along start and end of each spatial axis.  defaults to 0 along start and end of each spatial axis. 
45  48  * **strides**:  * **strides**: 
46  49  Stride along each spatial axis.  Stride along each spatial axis. 
47  50 


48  51  **Inputs**  **Inputs** 
49  52 


50  53  * **X** (heterogeneous)  **T**:  * **X** (heterogeneous)  **T**: 
51  54  Input data tensor from the previous operator; dimensions for image  Input data tensor from the previous operator; dimensions for image 
52  55  case are (N x C x H x W), where N is the batch size, C is the number  case are (N x C x H x W), where N is the batch size, C is the number 
53  56  of channels, and H and W are the height and the width of the data.  of channels, and H and W are the height and the width of the data. 
54  57  For non image case, the dimensions are in the form of (N x C x D1 x  For non image case, the dimensions are in the form of (N x C x D1 x 
55  58  D2 ... Dn), where N is the batch size. Optionally, if dimension  D2 ... Dn), where N is the batch size. Optionally, if dimension 
56  59  denotation is in effect, the operation expects the input data tensor  denotation is in effect, the operation expects the input data tensor 
57  60  to arrive with the dimension denotation of [DATA_BATCH,  to arrive with the dimension denotation of [DATA_BATCH, 
58  61  DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].  DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...]. 
59  62 


60  63  **Outputs**  **Outputs** 
61  64 


62  65  * **Y** (heterogeneous)  **T**:  * **Y** (heterogeneous)  **T**: 
63  66  Output data tensor from average or max pooling across the input  Output data tensor from average or max pooling across the input 
64  67  tensor. Dimensions will vary based on various kernel, stride, and  tensor. Dimensions will vary based on various kernel, stride, and 
65  68  pad sizes. Floor value of the dimension is used  pad sizes. Floor value of the dimension is used 
66  69 


67  70  **Type Constraints**  **Type Constraints** 
68  71 


69  72  * **T** in (  * **T** in ( 
70  73  tensor(double),  tensor(double), 
71  74  tensor(float),  tensor(float), 
72  75  tensor(float16)  tensor(float16) 
73  76  ):  ): 
74  77  Constrain input and output types to float tensors.  Constrain input and output types to float tensors. 
AveragePool  1#
Version
name: AveragePool (GitHub)
domain: main
since_version: 1
function: False
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 1.
Summary
AveragePool consumes an input tensor X and applies average pooling across the tensor according to kernel sizes, stride sizes, and pad lengths. average pooling consisting of computing the average on all values of a subset of the input tensor according to the kernel size and downsampling the data into the output tensor Y for further processing. The output spatial shape will be following:
output_spatial_shape[i] = floor((input_spatial_shape[i] + pad_shape[i]  kernel_spatial_shape[i]) / strides_spatial_shape[i] + 1)
* pad_shape[i] is sum of pads along axis i
auto_pad is a DEPRECATED attribute. If you are using them currently, the output spatial shape will be following:
VALID: output_spatial_shape[i] = ceil((input_spatial_shape[i]  kernel_spatial_shape[i] + 1) / strides_spatial_shape[i])
SAME_UPPER or SAME_LOWER: output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides_spatial_shape[i])
And pad shape will be following if SAME_UPPER or SAME_LOWER:
pad_shape[i] = (output_spatial_shape[i]  1) * strides_spatial_shape[i] + kernel_spatial_shape[i]  input_spatial_shape[i]
The output of each pooling window is divided by the number of elements exclude pad.
Attributes
auto_pad: auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. Where default value is NOTSET, which means explicit padding is used. SAME_UPPER or SAME_LOWER mean pad the input so that the output spatial size match the input.In case of odd number add the extra padding at the end for SAME_UPPER and at the beginning for SAME_LOWER. VALID mean no padding. Default value is
'NOTSET'
.kernel_shape (required): The size of the kernel along each axis.
pads: Padding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. pads format should be as follow [x1_begin, x2_begin…x1_end, x2_end,…], where xi_begin the number of pixels added at the beginning of axis i and xi_end, the number of pixels added at the end of axis i. This attribute cannot be used simultaneously with auto_pad attribute. If not present, the padding defaults to 0 along start and end of each spatial axis.
strides: Stride along each spatial axis.
Inputs
X (heterogeneous)  T: Input data tensor from the previous operator; dimensions for image case are (N x C x H x W), where N is the batch size, C is the number of channels, and H and W are the height and the width of the data. For non image case, the dimensions are in the form of (N x C x D1 x D2 … Dn), where N is the batch size. Optionally, if dimension denotation is in effect, the operation expects the input data tensor to arrive with the dimension denotation of [DATA_BATCH, DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE …].
Outputs
Y (heterogeneous)  T: Output data tensor from average or max pooling across the input tensor. Dimensions will vary based on various kernel, stride, and pad sizes. Floor value of the dimension is used
Type Constraints
T in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.