Shortcuts

MaxPool2d

class continual.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False, temporal_fill='zeros')[source]

Applies a Continual 2D max pooling over an input signal composed of several input planes.

In the simplest case, the output value of the layer with input size (N,C,T,S)(N, C, T, S), output (N,C,Tout,Sout)(N, C, T_{out}, S_{out}) and kernel_size (kT,kS)(kT, kS) can be precisely described as:

out(Ni,Cj,t,s)=maxm=0,,kT1maxn=0,,kS1input(Ni,Cj,stride[0]×t+m,stride[1]×s+n)\begin{aligned} out(N_i, C_j, t, s) ={} & \max_{m=0, \ldots, kT-1} \max_{n=0, \ldots, kS-1} \\ & \text{input}(N_i, C_j, \text{stride[0]} \times t + m, \text{stride[1]} \times s + n) \end{aligned}

The pooling over the TT dimension is continual (progressively cached) and the other is regular. If padding is non-zero, then the input is implicitly padded with negative infinity on both sides for padding number of points. dilation controls the spacing between the kernel points. It is harder to describe, but this link has a nice visualization of what dilation does.

Note

When stride > 1, the forward_step will only produce non-None values every stride steps.

Note

When ceil_mode=True, sliding windows are allowed to go off-bounds if they start within the left padding or the input. Sliding windows that would start in the right padded region are ignored.

The parameters kernel_size, stride, padding, dilation can either be:

  • a single int – in which case the same value is used for the height and width dimension

  • a tuple of two ints – in which case, the first int is used for the height dimension, and the second int for the width dimension

Parameters:
  • kernel_size (Union[int, Tuple[int, int]]) – the size of the window to take a max over

  • stride (Union[int, Tuple[int, int]]) – the stride of the window. Default value is kernel_size

  • padding (Union[int, Tuple[int, int]]) – implicit zero padding to be added on both sides

  • dilation (Union[int, Tuple[int, int]]) – a parameter that controls the stride of elements in the window

  • ceil_mode (bool) – when True, will use ceil instead of floor to compute the output shape

  • temporal_fill (PaddingMode) – How temporal states are initialized.

Shape:
  • Input: (N,C,Tin,Sin)(N, C, T_{in}, S_{in})

  • Output: (N,C,Tout,Sout)(N, C, T_{out}, S_{out}), where

    Tout=Tin+2padding[0]dilation[0]×(kernel_size[0]1)1stride[0]+1T_{out} = \left\lfloor\frac{T_{in} + 2 * \text{padding[0]} - \text{dilation[0]} \times (\text{kernel\_size[0]} - 1) - 1}{\text{stride[0]}} + 1\right\rfloor
    Sout=Sin+2padding[1]dilation[1]×(kernel_size[1]1)1stride[1]+1S_{out} = \left\lfloor\frac{S_{in} + 2 * \text{padding[1]} - \text{dilation[1]} \times (\text{kernel\_size[1]} - 1) - 1}{\text{stride[1]}} + 1\right\rfloor

Examples:

m = MaxPool2d(3, stride=2)
x = torch.randn(20, 16, 50, 32)
assert torch.allclose(m.forward(x), m.forward_steps(x))
Read the Docs v: latest
Versions
latest
stable
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.