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

Function sliding_window

imperative/python/megengine/functional/nn.py:1723–1757  ·  view source on GitHub ↗

r"""Extracts sliding local blocks from a batched input tensor. Refer to :class:`~.module.sliding_window.SlidingWindow` for more information. Args: inp: input tensor. kernel_size: size of the window. padding: implicit zero padding added on both sides of input. Defaul

(
    inp: Tensor,
    kernel_size: Union[int, Tuple[int, int]],
    padding: Union[int, Tuple[int, int]] = 0,
    stride: Union[int, Tuple[int, int]] = 1,
    dilation: Union[int, Tuple[int, int]] = 1,
)

Source from the content-addressed store, hash-verified

1721
1722
1723def sliding_window(
1724 inp: Tensor,
1725 kernel_size: Union[int, Tuple[int, int]],
1726 padding: Union[int, Tuple[int, int]] = 0,
1727 stride: Union[int, Tuple[int, int]] = 1,
1728 dilation: Union[int, Tuple[int, int]] = 1,
1729) -> Tensor:
1730 r"""Extracts sliding local blocks from a batched input tensor.
1731
1732 Refer to :class:`~.module.sliding_window.SlidingWindow` for more information.
1733
1734 Args:
1735 inp: input tensor.
1736 kernel_size: size of the window.
1737 padding: implicit zero padding added on both sides of input. Default: 0
1738 stride: stride of the window. Default: 1
1739 dilation: dilation of the window. Default: 1
1740 """
1741 padding_h, padding_w = expand_hw(padding)
1742 stride_h, stride_w = expand_hw(stride)
1743 dilation_h, dilation_w = expand_hw(dilation)
1744 window_h, window_w = expand_hw(kernel_size)
1745
1746 op = builtin.Images2Neibs(
1747 pad_h=padding_h,
1748 pad_w=padding_w,
1749 stride_h=stride_h,
1750 stride_w=stride_w,
1751 dilate_h=dilation_h,
1752 dilate_w=dilation_w,
1753 window_h=window_h,
1754 window_w=window_w,
1755 )
1756 (output,) = apply(op, inp)
1757 return output
1758
1759
1760def sliding_window_transpose(

Callers 1

forwardMethod · 0.85

Calls 2

expand_hwFunction · 0.85
applyFunction · 0.50

Tested by

no test coverage detected