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.

PR

Just a small problem.

I can fix it online!

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.mint.nn.functional.avg_pool2d

View Source On Gitee
mindspore.mint.nn.functional.avg_pool2d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True, divisor_override=None)[source]

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 (N,C,Hin,Win) , outputs regional average in the (Hin,Win) -dimension. Given kernel size (kH,kW) and stride , the operation is as follows.

Note

On the Atlas platform, when calculating the input, the precision is degraded from float32 to float16.

output(Ni,Cj,h,w)=1kHkWm=0kH1n=0kW1input(Ni,Cj,stride[0]×h+m,stride[1]×w+n)
Parameters
  • input (Tensor) – Tensor of shape (N,C,Hin,Win) or (C,Hin,Win).

  • kernel_size (Union[int, tuple[int], list[int]]) – The size of kernel used to take the average value. Can be a single number or a tuple (kH,kW) .

  • stride (Union[int, tuple[int], list[int]], optional) – The distance of kernel moving. Can be a single number or a tuple (sH,sW) . Default: None, where its value is equal to kernel_size.

  • padding (Union[int, tuple[int], list[int]], optional) – Implicit zero padding to be added on both sides. Can be a single number or a tuple (padH,padW) . Default: 0.

  • ceil_mode (bool, optional) – If True, apply ceil instead of floor to compute the output shape. Default: False.

  • count_include_pad (bool, optional) – If True, include the zero-padding in the averaging calculation. Default: True .

  • divisor_override (int, optional) – If specified, it will be used as divisor in the averaging calculation, otherwise size of pooling region will be used. Default: None.

Returns

Tensor, with shape (N,C,Hout,Wout) or (C,Hout,Wout).

Hout=Hin+2×padding[0]kernel_size[0]stride[0]+1Wout=Win+2×padding[1]kernel_size[1]stride[1]+1

Raises
  • TypeError – If input is not a Tensor.

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

  • TypeError – If ceil_mode or count_include_pad is not a bool.

  • TypeError – If divisor_override is not an int or None.

  • ValueError – If the dimension of input is not equal to 3 or 4.

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

  • ValueError – If value of padding is less than 0.

  • ValueError – If kernel_size, padding or stride is a tuple whose length is not equal to 1 or 2.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape(1, 3, 3, 4), mindspore.float32)
>>> output = mint.nn.functional.avg_pool2d(x, kernel_size=2, stride=1)
>>> 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]]]]