One-dimensional convolutional neural network

Please add image description

Assume that the input data dimension is 8 and the filter dimension is 5;
without padding, the output dimension is 4. If the number of filters is 16, then the shape of the output data is 4*16.

One-dimensional convolution does not mean that the convolution kernel has only one dimension, nor does it mean that the feature being convolved is also one-dimensional. One-dimensional means that the direction of convolution is one-dimensional. The one-dimensional convolution kernel can only move in a single one-dimensional direction of left and right.

torch.nn.Conv1d(
    in_channels: int,
    out_channels: int,
    kernel_size: _size_1_t,
    stride: _size_1_t = 1,
    padding: _size_1_t | str = 0,
    dilation: _size_1_t = 1,
    groups: int = 1,
    bias: bool = True,
    padding_mode: str = 'zeros',
    device: Any | None = None,
    dtype: Any | None = None
)

nn.Conv1d(
    in_channels=32,
    out_channels=128,
    kernel_size=20,
    stride=1,
    padding='same',

In the code, the out_channels parameter of nn.Conv1d specifies the number of convolution kernels, not the number of output channels. Therefore, for each convolution kernel, it generates an output channel. In your example, there are 128 convolution kernels, so 128 output channels will be generated.

The number of input channels is specified by the in_channels parameter, which represents the number of channels of input data. In your example, the number of input channels is 32.

To summarize, the out_channels parameter in nn.Conv1d controls the number of convolution kernels, and each convolution kernel generates an output channel. The number of input channels is specified by the in_channels parameter. In your example, there are 128 convolution kernels and therefore 128 output channels.

Guess you like

Origin blog.csdn.net/aqiangdeba/article/details/133322373