MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / avgpooling

Function avgpooling

imperative/python/megengine/xla/rules/nn.py:411–434  ·  view source on GitHub ↗
(
    inp,
    stride,
    kernel,
    padding,
    count_include_pad,
    base_dilation=None,
    kernel_dilation=None,
    oshape=None,
)

Source from the content-addressed store, hash-verified

409
410
411def avgpooling(
412 inp,
413 stride,
414 kernel,
415 padding,
416 count_include_pad,
417 base_dilation=None,
418 kernel_dilation=None,
419 oshape=None,
420):
421 sum_pool = sumpooling(
422 inp, stride, kernel, padding, base_dilation, kernel_dilation, oshape=oshape
423 )
424 if count_include_pad:
425 ret = sum_pool / float(np.prod(kernel))
426 else:
427 # for inp[a,b,c,d], kernel[1,1,2,2], oshape[a,b,e,f]
428 # div_ishape=[1,1,c,d], div_oshape=[1,1,e,f]
429 div_ishape = [i if k != 1 else 1 for (k, i) in zip(kernel, inp.shape)]
430 div_oshape = [o if k != 1 else 1 for (k, o) in zip(kernel, oshape)]
431 divider = fill(1.0, div_ishape, inp.dtype)
432 divider = sumpooling(divider, stride, kernel, padding, oshape=div_oshape)
433 ret = sum_pool / divider
434 return ret.astype(inp.dtype)
435
436
437def _get_adaptive_pool_param(ishape, oshape, tensor_format):

Callers 2

adaptive_pooling_lowerFunction · 0.85
pooling_lowerFunction · 0.85

Calls 3

fillFunction · 0.85
prodMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected