AdaptiveAvgPool1d

AdaptiveAvgPool1d#

class brainstate.nn.AdaptiveAvgPool1d(target_size, channel_axis=-1, name=None, in_size=None)#

Applies a 1D adaptive average pooling over an input signal composed of several input planes.

The output size is \(L_{out}\), for any input size. The number of output features is equal to the number of input planes.

Adaptive pooling automatically computes the kernel size and stride to achieve the desired output size, making it useful for creating fixed-size representations from variable-sized inputs.

Shape:
  • Input: \((N, L_{in}, C)\) or \((L_{in}, C)\).

  • Output: \((N, L_{out}, C)\) or \((L_{out}, C)\), where \(L_{out}=\text{target\_size}\).

Parameters:
  • target_size (int | Sequence[int]) – The target output size. The number of output features for each channel.

  • channel_axis (int | None) – Axis of the spatial channels for which pooling is skipped. If None, there is no channel axis. Default: -1

  • name (str | None) – The name of the module.

  • in_size (Sequence[int] | None) – The shape of the input tensor for shape inference.

Examples

>>> import brainstate
>>> # Target output size of 5
>>> m = AdaptiveAvgPool1d(5)
>>> input = brainstate.random.randn(1, 64, 8)
>>> output = m(input)
>>> output.shape
(1, 5, 8)
>>> # Can handle variable input sizes
>>> input2 = brainstate.random.randn(1, 32, 8)
>>> output2 = m(input2)
>>> output2.shape
(1, 5, 8)  # Same output size regardless of input size

See also

AvgPool1d

Non-adaptive 1D average pooling.

AdaptiveMaxPool1d

Adaptive 1D max pooling.