If I write a function using 'class Name(nn.Module)' and then call it 3 times, will each call have its own parameters or will they share parameters?

Ok so I create a class and within the init I define some conv blocks (which are also classes). For example:

class WienerFilter(nn.Module):
    def __init__(self):
        super(WienerFilter, self).__init__()

        self.relu = nn.ReLU()
        self.relu2 = nn.LeakyReLU()
        self.bn = nn.BatchNorm2d(1)
        self.coringa = ConvBlock(2, 1, kernel_size=1, padding=0, with_bn=False)
    def forward(self, I, noise_std, block_size):
        example = self.coring(I)
        return example

If in another class I do:

class test(nn.module):
    def __init__(self):
         self.wiener_filter = WienerFilter()
    def forward(self, input_image, std):
        WINDOW_SIZE = 16
        filteringa = self.wiener_filter(t_map, std, WINDOW_SIZE)
        WINDOW_SIZE = 16
        filteringb = self.wiener_filter(t_map, std, WINDOW_SIZE)
        # WINDOW_SIZE = 32
        # filteringc = self.wiener_filter(t_map, std, WINDOW_SIZE)

My question is, will ‘coringa’ be considered a new filter/convolution or will the same filter be used in each of the 3 calls of the function.


Everytime you instantiate the class WienerFilter() it will call the __init__ function and thus create a new set of Paramters.

1 Like

Thanks, I appreciate the quick repsonse. I fat fingered my post as I was typing it out and only finished it there. You answered my question though! I know it was more of a pythonic question!