Browse Source

docs(mge): update AvgPool2d & functional.nn.avg_pool2d example

GitOrigin-RevId: e2859c7f99
release-1.11.1
Megvii Engine Team 2 years ago
parent
commit
ada54ba5a0
2 changed files with 12 additions and 2 deletions
  1. +3
    -2
      imperative/python/megengine/functional/nn.py
  2. +9
    -0
      imperative/python/megengine/module/pooling.py

+ 3
- 2
imperative/python/megengine/functional/nn.py View File

@@ -709,8 +709,9 @@ def avg_pool2d(
output tensor of shape :math:`(N, C, H_{\text{out}}, W_{\text{out}})`. output tensor of shape :math:`(N, C, H_{\text{out}}, W_{\text{out}})`.


Examples: Examples:
>>> input = Tensor(np.arange(1 * 1 * 3 * 4).astype(np.float32).reshape(1, 1, 3, 4))
>>> F.avg_pool2d(input, kernel_size=2, stride=2, padding=[1,0], mode="average")
>>> import numpy as np
>>> inp = Tensor(np.arange(1 * 1 * 3 * 4).astype(np.float32).reshape(1, 1, 3, 4))
>>> F.avg_pool2d(inp, kernel_size=2, stride=2, padding=[1,0], mode="average")
Tensor([[[[0.25 1.25] Tensor([[[[0.25 1.25]
[6.5 8.5 ]]]], device=xpux:0) [6.5 8.5 ]]]], device=xpux:0)
""" """


+ 9
- 0
imperative/python/megengine/module/pooling.py View File

@@ -88,6 +88,15 @@ class AvgPool2d(_PoolNd):
mode: whether to include the padding values while calculating the average, set mode: whether to include the padding values while calculating the average, set
to "average" will do counting. to "average" will do counting.
Default: "average_count_exclude_padding" Default: "average_count_exclude_padding"

Examples:
>>> import numpy as np
>>> m = M.AvgPool2d(kernel_size=2, stride=2, padding=[1,0], mode="average")
>>> inp = mge.tensor(np.arange(1 * 1 * 3 * 4).astype(np.float32).reshape(1, 1, 3, 4))
>>> output = m(inp)
Tensor([[[[0.25 1.25]
[6.5 8.5 ]]]], device=xpux:0)

""" """


def __init__( def __init__(


Loading…
Cancel
Save