.. _l-onnx-doc-AveragePool: =========== AveragePool =========== .. contents:: :local: .. _l-onnx-op-averagepool-11: 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** .. raw:: html
00AveragePool consumes an input tensor X and applies average pooling acrossAveragePool consumes an input tensor X and applies average pooling across
11the tensor according to kernel sizes, stride sizes, and pad lengths.the tensor according to kernel sizes, stride sizes, and pad lengths.
22average pooling consisting of computing the average on all values of aaverage pooling consisting of computing the average on all values of a
33subset of the input tensor according to the kernel size and downsampling thesubset of the input tensor according to the kernel size and downsampling the
44data 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:
55::::
66
77 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)
88
99oror
1010::::
1111
1212 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)
1313
1414if ceil_mode is enabledif ceil_mode is enabled
1515
1616::::
1717
1818 * pad_shape[i] is sum of pads along axis i * pad_shape[i] is sum of pads along axis i
1919
2020auto_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:
2121::::
2222
2323 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])
2424 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])
2525
2626And pad shape will be following if SAME_UPPER or SAME_LOWER:And pad shape will be following if SAME_UPPER or SAME_LOWER:
2727::::
2828
2929 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]
3030
3131The 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).
3232
3333**Attributes****Attributes**
3434
3535* **auto_pad**:* **auto_pad**:
3636 auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
3737 Where default value is NOTSET, which means explicit padding is used. Where default value is NOTSET, which means explicit padding is used.
3838 SAME_UPPER or SAME_LOWER mean pad the input so that the output SAME_UPPER or SAME_LOWER mean pad the input so that output_shape[i]
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,
4042 padding at the end for SAME_UPPER and at the beginning for the extra padding is added at the end for SAME_UPPER and at the
4143 SAME_LOWER. VALID mean no padding. Default value is 'NOTSET'. beginning for SAME_LOWER. Default value is 'NOTSET'.
4244* **ceil_mode**:* **ceil_mode**:
4345 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.
4446* **count_include_pad**:* **count_include_pad**:
4547 Whether include pad pixels when calculating values for the edges. Whether include pad pixels when calculating values for the edges.
4648 Default is 0, doesn't count include pad. Default value is 0. Default is 0, doesn't count include pad. Default value is 0.
4749* **kernel_shape** (required):* **kernel_shape** (required):
4850 The size of the kernel along each axis. The size of the kernel along each axis.
4951* **pads**:* **pads**:
5052 Padding for the beginning and ending along each spatial axis, it can Padding for the beginning and ending along each spatial axis, it can
5153 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
5254 number of pixels added to the beginning and end part of the number of pixels added to the beginning and end part of the
5355 corresponding axis. pads format should be as follow [x1_begin, corresponding axis. pads format should be as follow [x1_begin,
5456 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
5557 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
5658 added at the end of axis i. This attribute cannot be used added at the end of axis i. This attribute cannot be used
5759 simultaneously with auto_pad attribute. If not present, the padding simultaneously with auto_pad attribute. If not present, the padding
5860 defaults to 0 along start and end of each spatial axis. defaults to 0 along start and end of each spatial axis.
5961* **strides**:* **strides**:
6062 Stride along each spatial axis. Stride along each spatial axis. If not present, the stride defaults
63 to 1 along each spatial axis.
6164
6265**Inputs****Inputs**
6366
6467* **X** (heterogeneous) - **T**:* **X** (heterogeneous) - **T**:
6568 Input data tensor from the previous operator; dimensions for image Input data tensor from the previous operator; dimensions for image
6669 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
6770 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.
6871 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
6972 D2 ... Dn), where N is the batch size. Optionally, if dimension D2 ... Dn), where N is the batch size. Optionally, if dimension
7073 denotation is in effect, the operation expects the input data tensor denotation is in effect, the operation expects the input data tensor
7174 to arrive with the dimension denotation of [DATA_BATCH, to arrive with the dimension denotation of [DATA_BATCH,
7275 DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...]. DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
7376
7477**Outputs****Outputs**
7578
7679* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
7780 Output data tensor from average or max pooling across the input Output data tensor from average or max pooling across the input
7881 tensor. Dimensions will vary based on various kernel, stride, and tensor. Dimensions will vary based on various kernel, stride, and
7982 pad sizes. Floor value of the dimension is used pad sizes. Floor value of the dimension is used
8083
8184**Type Constraints****Type Constraints**
8285
8386* **T** in (* **T** in (
8487 tensor(double), tensor(double),
8588 tensor(float), tensor(float),
8689 tensor(float16) tensor(float16)
8790 ): ):
8891 Constrain input and output types to float tensors. Constrain input and output types to float tensors.
.. _l-onnx-op-averagepool-10: 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** .. raw:: html
00AveragePool consumes an input tensor X and applies average pooling acrossAveragePool consumes an input tensor X and applies average pooling across
11the tensor according to kernel sizes, stride sizes, and pad lengths.the tensor according to kernel sizes, stride sizes, and pad lengths.
22average pooling consisting of computing the average on all values of aaverage pooling consisting of computing the average on all values of a
33subset of the input tensor according to the kernel size and downsampling thesubset of the input tensor according to the kernel size and downsampling the
44data 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:
55::::
66
77 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)
88
9or
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
14if ceil_mode is enabled
15
16::
17
918 * pad_shape[i] is sum of pads along axis i * pad_shape[i] is sum of pads along axis i
1019
1120auto_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:
1221::::
1322
1423 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])
1524 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])
1625
1726And pad shape will be following if SAME_UPPER or SAME_LOWER:And pad shape will be following if SAME_UPPER or SAME_LOWER:
1827::::
1928
2029 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]
2130
2231The 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).
2332
2433**Attributes****Attributes**
2534
2635* **auto_pad**:* **auto_pad**:
2736 auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
2837 Where default value is NOTSET, which means explicit padding is used. Where default value is NOTSET, which means explicit padding is used.
2938 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
3039 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
3140 padding at the end for SAME_UPPER and at the beginning for padding at the end for SAME_UPPER and at the beginning for
3241 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.
3344* **count_include_pad**:* **count_include_pad**:
3445 Whether include pad pixels when calculating values for the edges. Whether include pad pixels when calculating values for the edges.
3546 Default is 0, doesn't count include pad. Default value is 0. Default is 0, doesn't count include pad. Default value is 0.
3647* **kernel_shape** (required):* **kernel_shape** (required):
3748 The size of the kernel along each axis. The size of the kernel along each axis.
3849* **pads**:* **pads**:
3950 Padding for the beginning and ending along each spatial axis, it can Padding for the beginning and ending along each spatial axis, it can
4051 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
4152 number of pixels added to the beginning and end part of the number of pixels added to the beginning and end part of the
4253 corresponding axis. pads format should be as follow [x1_begin, corresponding axis. pads format should be as follow [x1_begin,
4354 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
4455 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
4556 added at the end of axis i. This attribute cannot be used added at the end of axis i. This attribute cannot be used
4657 simultaneously with auto_pad attribute. If not present, the padding simultaneously with auto_pad attribute. If not present, the padding
4758 defaults to 0 along start and end of each spatial axis. defaults to 0 along start and end of each spatial axis.
4859* **strides**:* **strides**:
4960 Stride along each spatial axis. Stride along each spatial axis.
5061
5162**Inputs****Inputs**
5263
5364* **X** (heterogeneous) - **T**:* **X** (heterogeneous) - **T**:
5465 Input data tensor from the previous operator; dimensions for image Input data tensor from the previous operator; dimensions for image
5566 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
5667 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.
5768 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
5869 D2 ... Dn), where N is the batch size. Optionally, if dimension D2 ... Dn), where N is the batch size. Optionally, if dimension
5970 denotation is in effect, the operation expects the input data tensor denotation is in effect, the operation expects the input data tensor
6071 to arrive with the dimension denotation of [DATA_BATCH, to arrive with the dimension denotation of [DATA_BATCH,
6172 DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...]. DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
6273
6374**Outputs****Outputs**
6475
6576* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
6677 Output data tensor from average or max pooling across the input Output data tensor from average or max pooling across the input
6778 tensor. Dimensions will vary based on various kernel, stride, and tensor. Dimensions will vary based on various kernel, stride, and
6879 pad sizes. Floor value of the dimension is used pad sizes. Floor value of the dimension is used
6980
7081**Type Constraints****Type Constraints**
7182
7283* **T** in (* **T** in (
7384 tensor(double), tensor(double),
7485 tensor(float), tensor(float),
7586 tensor(float16) tensor(float16)
7687 ): ):
7788 Constrain input and output types to float tensors. Constrain input and output types to float tensors.
.. _l-onnx-op-averagepool-7: 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** .. raw:: html
00AveragePool consumes an input tensor X and applies average pooling acrossAveragePool consumes an input tensor X and applies average pooling across
11the tensor according to kernel sizes, stride sizes, and pad lengths.the tensor according to kernel sizes, stride sizes, and pad lengths.
22average pooling consisting of computing the average on all values of aaverage pooling consisting of computing the average on all values of a
33subset of the input tensor according to the kernel size and downsampling thesubset of the input tensor according to the kernel size and downsampling the
44data 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:
55::::
66
77 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)
88
99 * pad_shape[i] is sum of pads along axis i * pad_shape[i] is sum of pads along axis i
1010
1111auto_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:
1212::::
1313
1414 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])
1515 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])
1616
1717And pad shape will be following if SAME_UPPER or SAME_LOWER:And pad shape will be following if SAME_UPPER or SAME_LOWER:
1818::::
1919
2020 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]
2121
2222The output of each pooling window is divided by the number of elements exclude pad.The output of each pooling window is divided by the number of elements (exclude pad when attribute count_include_pad is zero).
2323
2424**Attributes****Attributes**
2525
2626* **auto_pad**:* **auto_pad**:
2727 auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID. auto_pad must be either NOTSET, SAME_UPPER, SAME_LOWER or VALID.
2828 Where default value is NOTSET, which means explicit padding is used. Where default value is NOTSET, which means explicit padding is used.
2929 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
3030 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
3131 padding at the end for SAME_UPPER and at the beginning for padding at the end for SAME_UPPER and at the beginning for
3232 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.
3336* **kernel_shape** (required):* **kernel_shape** (required):
3437 The size of the kernel along each axis. The size of the kernel along each axis.
3538* **pads**:* **pads**:
3639 Padding for the beginning and ending along each spatial axis, it can Padding for the beginning and ending along each spatial axis, it can
3740 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
3841 number of pixels added to the beginning and end part of the number of pixels added to the beginning and end part of the
3942 corresponding axis. pads format should be as follow [x1_begin, corresponding axis. pads format should be as follow [x1_begin,
4043 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
4144 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
4245 added at the end of axis i. This attribute cannot be used added at the end of axis i. This attribute cannot be used
4346 simultaneously with auto_pad attribute. If not present, the padding simultaneously with auto_pad attribute. If not present, the padding
4447 defaults to 0 along start and end of each spatial axis. defaults to 0 along start and end of each spatial axis.
4548* **strides**:* **strides**:
4649 Stride along each spatial axis. Stride along each spatial axis.
4750
4851**Inputs****Inputs**
4952
5053* **X** (heterogeneous) - **T**:* **X** (heterogeneous) - **T**:
5154 Input data tensor from the previous operator; dimensions for image Input data tensor from the previous operator; dimensions for image
5255 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
5356 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.
5457 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
5558 D2 ... Dn), where N is the batch size. Optionally, if dimension D2 ... Dn), where N is the batch size. Optionally, if dimension
5659 denotation is in effect, the operation expects the input data tensor denotation is in effect, the operation expects the input data tensor
5760 to arrive with the dimension denotation of [DATA_BATCH, to arrive with the dimension denotation of [DATA_BATCH,
5861 DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...]. DATA_CHANNEL, DATA_FEATURE, DATA_FEATURE ...].
5962
6063**Outputs****Outputs**
6164
6265* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
6366 Output data tensor from average or max pooling across the input Output data tensor from average or max pooling across the input
6467 tensor. Dimensions will vary based on various kernel, stride, and tensor. Dimensions will vary based on various kernel, stride, and
6568 pad sizes. Floor value of the dimension is used pad sizes. Floor value of the dimension is used
6669
6770**Type Constraints****Type Constraints**
6871
6972* **T** in (* **T** in (
7073 tensor(double), tensor(double),
7174 tensor(float), tensor(float),
7275 tensor(float16) tensor(float16)
7376 ): ):
7477 Constrain input and output types to float tensors. Constrain input and output types to float tensors.
.. _l-onnx-op-averagepool-1: 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.