Extract local temporal patterns from waveform and time-series channels.
Audio or sensor streams
PyTorch · Class
nn.Conv1d applies learnable one-dimensional filters to multi-channel signals. It converts C_in input channels into C_out output channels while stride, padding, dilation, and groups control how the filters scan and connect.
Conv1d slides learnable one-dimensional filters across the last dimension of an input with one or optionally two leading dimensions. It produces the requested number of output channels, while stride, padding, dilation, and groups control sampling, boundary extension, receptive-field spacing, and channel connectivity.
class torch.nn.modules.conv.Conv1d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)| Name | Type | Description |
|---|---|---|
in_channels | int | Number of channels in the input image. |
out_channels | int | Number of channels produced by the convolution. |
kernel_size | int or tuple | Size of the convolving kernel. |
stride | int or tuple | Stride of the convolution; default 1. |
padding | int, tuple, or str | Padding added to both sides of the input; default 0. |
dilation | int or tuple | Spacing between kernel elements; default 1. |
groups | int | Number of blocked connections from input channels to output channels; default 1. |
bias | bool | Whether to add a learnable output bias; default True. |
padding_mode | str | Padding mode: zeros, reflect, replicate, or circular; default zeros. |
device | torch.device or None | Optional device for created parameters. |
dtype | torch.dtype or None | Optional data type for created parameters. |
A tensor with shape (N, C_out, L_out) for batched input or (C_out, L_out) for unbatched input.
import torch
from torch import nn
layer = nn.Conv1d(in_channels=2, out_channels=4, kernel_size=3, padding=1)
x = torch.randn(5, 2, 16)
y = layer(x)
print(y.shape) # torch.Size([5, 4, 16])Creates a one-dimensional convolution that maps two input channels to four output channels while preserving length through padding.
Audio or sensor streams
Sequence feature extraction
Grouped channel processing
Conv1d applies a one-dimensional convolution over an input signal. Its input can have shape (N, C_in, L_in) or (C_in, L_in), and the output has the corresponding channel count C_out.
Follow-up: How do groups change connectivity? They partition input and output channels into independent connection groups, and both channel counts must be divisible by groups.
in_channels is the number of input channels, out_channels is the number produced, and kernel_size specifies the filter width. Stride, padding, and dilation respectively control movement, boundary padding, and spacing between kernel elements.
Follow-up: What is the effect of increasing dilation while holding kernel size fixed? It expands the filter's receptive field by spacing its kernel elements farther apart.
The layer adds a learnable bias by default because bias=True. Setting bias=False omits that additive parameter, which can be useful when another component supplies the offset.
Follow-up: Which padding modes are documented? The supported choices are zeros, reflect, replicate, and circular.
torch.nn.Conv1dtorch.nn.Conv2dtorch.nn.Conv3dtorch.nn.ConvTranspose1dtorch.nn.functional.conv1d