I am new to PyTorch.
I see that nn.Conv2d function takes as argument a pytorch tensor x, and params as in_channels, along with others.
My question is that, since the function performs a 2D convolution, the in_channels would always be equal to the channel depth of the input tensor x, so why do we need to specify the same as a parameter?
It is because nn.Conv2d in essence uses a 3d filter i.e filter_size x filter_size x input_channels. And as @alan_ayu pointed out, you need filter size, input channels and output channels to define Conv2d’s parameters.
I believe every channel of let’s say an RGB image contribute to the overall properties of that image meaning all of the channels must be taken into account when performing the convolution process. Let’s say you just have one filter, a convolution process applies that filter into all of the 3 channels which will output 3 difference results of same dimension and those 3 results are added.