Why is there additional parameter in torch.nn.Model

I found there seems to be one additional parameter in the torch.nn.Model for convnet as shown in the example below. And the shape the additional parameter seems like [in_channel, out_channl]. Can anyone help explain this?

Thanks in advance!

conv1 = torch.nn.Conv2d(1, 2, 1)
print("conv1:", conv1.weight)

class myModel(torch.nn.Module):
    def __init__(self):
        super(myModel, self).__init__()
        self.conv1 = torch.nn.Conv2d(1, 2, 1)
    def forward(self, x):
        return torch.nn.functional.conv2d(x, self.filter)

model = myModel()# .cuda()
print("model:", [i for i in model.parameters()])

The output or first print is:

conv1: Parameter containing:
        [[[ 0.2480]]]], requires_grad=True)

The output of second print is:

model: [Parameter containing:
tensor([[[[ 0.9591]]],
        [[[-0.9882]]]], requires_grad=True), Parameter containing:
tensor([0.3482, 0.2676], requires_grad=True)]


The second parameter is the bias. You can access it with conv1.bias.
It has the same size as the number of output channels (it is created here).
You can pass bias=False to the conv2d constructor if you don’t want it.

I almost forget about that and Thank you :joy: