Reputation: 181
From the PyTorch documentation for Convolution, I see the function torch.nn.Conv1d
requires users to pass the parameters in_channels
and out_channels
.
I know these refer to "input channels" and "output channels", but I am not sure what they mean in the context of a convolution. My guess is that in_channels
is equivalent to the input features and out_channels
is equivalent to the output features, but I am not sure.
Could someone explain what thse arguments refer to?
Upvotes: 7
Views: 12544
Reputation: 24301
Given a convolution of:
m
N
input channels / signals / variablesP
channels / features / filtersyou would use:
nn.Conv1d(in_channels=N, out_channels=P, kernel_size=m)
This is illustrated for 2d images below in Deep Learning with PyTorch (where the kernels are of size 3x3xN (where N=3 for an RGB image), and there are 5 such kernels for the 5 outputs desired):
Upvotes: 5
Reputation: 8709
in_Channels
denotes the number of channels in the input image, while out_channels
denotes the number of channels produced by the convolution. In the case of image data, the most common cases are grayscale images which will have one channel, black, or color images that will have three channels – red, green, and blue. out_channels
is a matter of preference but there are some important things to note about it.
out_channels
allows the layer to potentially learn more useful features about the input data, though this is not a hard rule.in_channels
/out_channels
in each layer of your network and the number of layers.Upvotes: 2