SlidingWindow#

class SlidingWindow(kernel_size, padding=0, stride=1, dilation=1, **kwargs)[source]#

Apply a sliding window to input tensor and copy content in the window to corresponding output location. Assume input shape is \((N, C, IH, IW)\), then output shape would be \((N, C, OH, OW, window_h, window_w)\) where \((OH, OW)\) would be computed from padding, stride, window and \((IH, IW)\), as in convolution. For each output location, we have;

\[\begin{split}out_{n, c, oh, ow, wh, ww} &= src_{n, c, ih+wh, iw+ww} \\ \text{where } & ih=-pad_h+oh \times stride_h + (wh-1) \times (dilation_h-1) \\ & iw=-pad_w+ow \times stride_w + (ww-1) \times (dilation_w-1)\end{split}\]
Parameters:

Example

>>> import numpy as np
>>> inp = Tensor(np.arange(30).reshape(1,1,5,6))
>>> op = M.SlidingWindow(kernel_size=3, padding=1, stride=2, dilation=2)
>>> out = op(inp)
>>> print(out.numpy())
[[[[[[ 0  0  0]
     [ 0  7  9]
     [ 0 19 21]]

    [[ 0  0  0]
     [ 7  9 11]
     [19 21 23]]]


   [[[ 0  7  9]
     [ 0 19 21]
     [ 0  0  0]]

    [[ 7  9 11]
     [19 21 23]
     [ 0  0  0]]]]]]