What does the "affine" parameter do in PyTorch nn.BatchNorm2d?
What is the purpose of the affine argument and what does it do?
class DilConv(nn.Module):
    def __init__(self, in_C, out_C, kernel_size, stride, padding, affine=True):
        super(DilConv, self).__init__()
        self.ops = nn.Sequential(
          nn.ReLU(),
          nn.Conv2d(in_C, in_C, kernel_size=kernel_size, stride=stride, 
                    padding=padding, dilation=2, groups=in_C, bias=False),
          nn.Conv2d(in_C, out_C, kernel_size=1, bias=False),
          nn.BatchNorm2d(out_C, affine=affine))
        
    def forward(self, x):
        return self.ops(x)


If you look at the documentation page for BatchNorm2d, you will read:

affine – a boolean value that when set to True, this module has learnable affine parameters. Default: True

Checking the source code on the base class _NormBase, you will see parameters weight and bias are only defined if the argument affine is set to True. These parameters correspond to gamma and beta in the documentation formulae.
