class
AvgPool1d
extends
ModuleAvgPool1d(kernel_size: int, stride: int | None = None, padding: int = 0, ceil_mode: bool = False, count_include_pad: bool = True)Applies 1-D average pooling over a sequence.
For each output position the module computes the arithmetic mean of
the values in a sliding window of length kernel_size:
where is the effective window size (see
count_include_pad) and is stride.
The output length follows:
Parameters
kernel_sizeintSize of the averaging window.
strideint or None= NoneStep between successive windows. Defaults to
kernel_size.paddingint= 0Zero-padding added to both ends of the input before pooling.
Default:
0.ceil_modebool= FalseUse ceiling instead of floor for the output length.
Default:
False.count_include_padbool= TrueIf
True (default), zero-padded values are counted in the
denominator. If False, only real input values are averaged.Attributes
kernel_sizeintstrideint or Nonepaddingintceil_modeboolcount_include_padboolNotes
- Input:
(N, C, L_in) - Output:
(N, C, L_out)
- When
count_include_pad=Truethe denominator always equalskernel_size, even for border windows that overlap the padding. Settingcount_include_pad=Falsecan produce slightly higher values near the boundaries. - Average pooling is commonly used in sequence models to obtain a fixed-size summary of variable-length inputs.
Examples
Non-overlapping average pooling:
>>> import lucid
>>> import lucid.nn as nn
>>> pool = nn.AvgPool1d(kernel_size=4)
>>> x = lucid.ones((1, 8, 16))
>>> y = pool(x)
>>> y.shape
(1, 8, 4)
Overlapping pooling with padding, excluding pad from average:
>>> pool = nn.AvgPool1d(kernel_size=3, stride=1, padding=1,
... count_include_pad=False)
>>> x = lucid.ones((2, 4, 10))
>>> y = pool(x)
>>> y.shape
(2, 4, 10)Methods (3)
dunder
__init__
→None__init__(kernel_size: int, stride: int | None = None, padding: int = 0, ceil_mode: bool = False, count_include_pad: bool = True)Initialise the AvgPool1d module. See the class docstring for parameter semantics.
fn
forward
→Tensorforward(x: Tensor)Apply the pooling operation to the input tensor.
Parameters
inputTensorInput tensor of shape where are the
spatial dimensions appropriate for this pooling layer.
Returns
TensorPooled output tensor.
fn
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.