What does out_channels in Conv2d represent?

import torch.nn.functional as F

class Net(nn.Module):
    def __init__(self):
        self.conv1 = nn.Conv2d(3, 6, 5)
        self.pool = nn.MaxPool2d(2, 2)
        self.conv2 = nn.Conv2d(6, 16, 5)
        self.fc1 = nn.Linear(16 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        x = self.pool(F.relu(self.conv1(x)))
        x = self.pool(F.relu(self.conv2(x)))
        x = torch.flatten(x, 1) # flatten all dimensions except batch
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

net = Net()

I am taking a look at PyTorch Blitz and in the conv1 layer we can see the input_channels=3 because it’s the first image so it just has its 3 RGB channels and out_channels=6.

Does that mean the number of filters I have are 6? In which case it’d mean the total number of feature maps I would get are 6*3==18? But if that is the case why in conv2 am I plugging in input_channels=6, shouldn’t I be plugging in 18 because that was the output from the previous Convolutional layer?

Yes, the out_channels represent the number of output channels and thus the number of filters in the default setup.

No, you would get out_channels activation maps, as each filter uses all input channels to create one output activation map (in the default setup; grouped convs would work in a different way).

You can watch torch.nn.Conv2d Module Explained

Thank you so much for your help, I understand it now.

Yes this helped me understand it as well, thank you.