AvgPool1d#
- class brainstate.nn.AvgPool1d(kernel_size, stride=1, padding='VALID', channel_axis=-1, name=None, in_size=None)#
Applies a 1D average pooling over an input signal composed of several input planes.
In the simplest case, the output value of the layer with input size \((N, L, C)\), output \((N, L_{out}, C)\) and
kernel_size\(k\) can be precisely described as:\[\text{out}(N_i, l, C_j) = \frac{1}{k} \sum_{m=0}^{k-1} \text{input}(N_i, \text{stride} \times l + m, C_j)\]If
paddingis non-zero, then the input is implicitly zero-padded on both sides forpaddingnumber of points.- Shape:
Input: \((N, L_{in}, C)\) or \((L_{in}, C)\).
Output: \((N, L_{out}, C)\) or \((L_{out}, C)\), where
\[L_{out} = \left\lfloor \frac{L_{in} + 2 \times \text{padding} - \text{kernel\_size}}{\text{stride}} + 1\right\rfloor\]
- Parameters:
kernel_size (
int|Sequence[int] |integer|Sequence[integer]) – An integer, or a sequence of integers defining the window to reduce over.stride (
int|Sequence[int]) – An integer, or a sequence of integers, representing the inter-window stride. Default: 1padding (
str|int|Tuple[int,...] |Sequence[Tuple[int,int]]) – Either the string ‘SAME’, the string ‘VALID’, or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension. Default: ‘VALID’channel_axis (
int|None) – Axis of the spatial channels for which pooling is skipped. IfNone, there is no channel axis. Default: -1in_size (
int|Sequence[int] |integer|Sequence[integer] |None) – The shape of the input tensor.
Examples
>>> import brainstate >>> # pool with window of size=3, stride=2 >>> m = AvgPool1d(3, stride=2) >>> input = brainstate.random.randn(20, 50, 16) >>> m(input).shape (20, 24, 16)