Passing variable to nn.Conv2d arguments within a class init definition python
So I want to pass some new variables such as kernel_size when I initiate a new object. Let's say net=Net10(5,2,4,3,1,1). so that I get an object of this class with the parameters I want not something always constant, cos otherwise I will have to define lots of classes. Now, I want to pass kernel_size within the self.Conv2d, and I get a syntax error: positional argument follows keyword argument
Does anyone know how to fix this? Should I change it all to functions instead of classes?

    class Net10(nn.Module):   
    def __init__ (self, kernel_size, stride, pooling, num_classes, neurons, ActFunn, *args):
        super(Net10, self).__init__()
        self.kernel = kernel_size
        self.stride = stride
        self.pooling = pooling
        self.num_classes = num_classes
        self.neurons = neurons
        self.Actfun = ActFunn   
        self.conv1 = nn.Conv2d(in_channels=1, out_channels=32, kernel, padding=2, stride=1)                 
        self.pool = nn.MaxPool2d(pooling, pooling)
        self.fcinput= round (28 / pooling)


Try:

self.conv1 = nn.Conv2d(in_channels=1, out_channels=32, kernel_size=self.kernel, padding=2, stride=1)


In more details: python functions (e.g., __init__ of the conv layer) can have input arguments is two "flavors": positional arguments: that is associating an input argument to a function variable according to its position in the argument list.
The other "flavor" is keyword argument: argument that is given with its keyword, e.g., in_channels=1 etc.

As a rule python does not allow wild mixing of positional and keyword arguments.
You can have positional arguments followed by keyword argument, but you cannot have a positional argument once you started declaring keyword arguments.

self.conv1 = nn.Conv2d(in_channels=1,   # keyword argument
   out_channels=32,   # keyword argument
   kernel,   # positional argument (no "keyword" defining this argument)
   padding=2,  # keyword
   stride=1)   # keyword

