Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.avg_pool2d

mindspore.ops.avg_pool2d(x, kernel_size=1, strides=1, pad_mode='valid', data_format='NCHW')[source]

Average pooling operation.

Applies a 2D average pooling over an input Tensor which can be regarded as a composition of 2D input planes. Typically the input is of shape (Nin,Cin,Hin,Win), outputs regional average in the (Hin,Win)-dimension. Given kernel size (kh,kw) and strides , the operation is as follows.

output(Ni,Cj,h,w)=1khkwm=0kh1n=0kw1input(Ni,Cj,strides[0]×h+m,strides[1]×w+n)

Warning

  • Global pooling is supported.

  • For Ascend, the height of kernel_size and the weight of kernel_size are positive integers within the range [1, 255]. ksize_h * ksize_w < 256.

  • For Ascend, due to instruction restrictions, the values of ‘strides_h’ and ‘strides_w’ are positive integers within the range [1, 63].

Parameters
  • x (Tensor) – Tensor of shape (N,Cin,Hin,Win).

  • kernel_size (Union[int, tuple[int]]) – The size of kernel used to take the average value. It is an int number that represents height and width of the kernel, or a tuple of two int numbers that represent height and width respectively. Default: 1.

  • strides (Union[int, tuple[int]]) – The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1.

  • pad_mode (str) –

    The optional value for pad mode, is ‘same’ or ‘valid’. Default: ‘valid’.

    • same: The height and width of the output are the same as the input divided by ‘strides’ and rounded up.

    • valid: Returns the output of the valid calculation without filling. Redundant pixels that do not satisfy the calculation will be discarded.

  • data_format (str) – The format of input and output data. It should be ‘NHWC’ or ‘NCHW’. Default: ‘NCHW’.

Returns

Tensor, with shape (N,Cout,Hout,Wout).

Raises
  • TypeError – If kernel_size or strides is neither int nor tuple.

  • ValueError – If kernel_size or strides is less than 1.

  • ValueError – If pad_mode is neither ‘valid’ nor ‘same’ with not case sensitive.

  • ValueError – If data_format is neither ‘NCHW’ nor ‘NHWC’.

  • ValueError – If length of shape of x is not equal to 4.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
>>> output = ops.avg_pool2d(x, kernel_size=2, strides=1, pad_mode='VALID')
>>> print(output)
[[[[ 2.5   3.5   4.5]
   [ 6.5   7.5   8.5]]
  [[14.5  15.5  16.5]
   [18.5  19.5  20.5]]
  [[26.5  27.5  28.5]
   [30.5  31.5  32.5]]]]