What happens when Conv2d filter number is not a multiple of the input channel?

A bit of context; reading literature, an input image 256x256x3 is passed through a convolution that produces 64 filters, 256x256x64. What happens when the number of filter is not a multiple of the input channels?

m = nn.Conv2d(3, 2, 3, 1)
input = torch.randn(1, 3, 10, 10)
output = m(input)

The code above has 2 filters and 3 layers: my current understanding is the last channel is not touched at all and if there was 5 filters, the channels before would each get convoluted twice.
Is this a problem? How does PyTorch handles this?

You misunderstand the application of Conv2d in virtually all ML frameworks today. Each filter takes all channels as input as opposed to just one, therefore, it has CxKxK parameters. If you want to use a subset, that’s what the groups parameter is for. Then it needs to be a multiple.

1 Like