mindspore.ops.AdaptiveAvgPool2D
- class mindspore.ops.AdaptiveAvgPool2D(output_size)[source]
AdaptiveAvgPool2D operation.
This operator applies a 2D adaptive average pooling to an input signal composed of multiple input planes. That is, for any input size, the size of the specified output is H x W. The number of output features is equal to the number of input planes.
- Parameters
output_size (Union[int, tuple]) – The target output size is H x W. ouput_size can be a tuple, or a single H for H x H, and H and W can be int or None which means the output size is the same as the input.
- Inputs:
input_x (Tensor) - The input of AdaptiveAvgPool2D, which is a 3D or 4D tensor, with float16, float32, float64 data type.
- Outputs:
Tensor, with the same type as the input_x.
Shape of the output is input_x_shape[:len(input_x_shape) - len(out_shape)] + out_shape.
If output_size contains None:
out_shape = input_x_shape[-2] + output_size[1]: If output_size is (None, w)
out_shape = output_size[0] + input_x_shape[-1]: If output_size is (h, None)
out_shape = input_x_shape[-2:]: If output_size is (None, None)
If output_size does not contain None:
out_shape = (h, h): If output_size is h
out_shape = (h, w): If output_size is (h, w)
- Raises
ValueError – If output_size is a tuple and if output_size length is not 2.
TypeError – If input_x is not a tensor.
TypeError – If dtype of input_x is not float16, float32, float64.
ValueError – If input_x dimension is less than or equal to output_size dimension.
- Supported Platforms:
GPU
Examples
>>> # case 1: output_size=(None, 2) >>> input_x = Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]], ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]], ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]), mindspore.float32) >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((None, 2)) >>> output = adaptive_avg_pool_2d(input_x) >>> print(output) [[[1.5 2.5] [4.5 5.5] [7.5 8.5]] [[1.5 2.5] [4.5 5.5] [7.5 8.5]] [[1.5 2.5] [4.5 5.5] [7.5 8.5]]] >>> # case 2: output_size=2 >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D(2) >>> output = adaptive_avg_pool_2d(input_x) >>> print(output) [[[3. 4.] [6. 7.]] [[3. 4.] [6. 7.]] [[3. 4.] [6. 7.]]] >>> # case 3: output_size=(1, 2) >>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((1, 2)) >>> output = adaptive_avg_pool_2d(input_x) >>> print(output) [[[4.5 5.5]] [[4.5 5.5]] [[4.5 5.5]]]