Difference between two implemantations of Seq layers - pytorch
I have implemented a model using the traditional way of implementation. and the code is like this.
    def __init__(self):
    super(enhance_net_nopool, self).__init__()
    number_f = 32
    
    self.relu = nn.ReLU(inplace=True)
    self.e_conv1 = nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True)
    self.e_conv2 = nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True)
    self.e_conv3 = nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True)
    
def forward(self, x):
    x1 = self.relu(self.e_conv1(x))
    x2 = self.relu(self.e_conv2(x1))
    x3 = self.relu(self.e_conv3(x2))

I need to know is it possible to rewrite that code using
seq_layers=nn.Sequential(*layers)

this *layers.
If it's implemented like this.
self.conv_block = [
        relu = nn.ReLU(inplace=True)
        conv = nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True)
    ]

are they the same?

Your code can be rewritten as:
layers = [nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True), nn.ReLU(inplace=True), 
    nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True), nn.ReLU(inplace=True), 
    nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True), nn.ReLU(inplace=True)
]

seq_layers = nn.Sequential(*layers)

or
def get_conv(number_f):
    return nn.Sequential(
                nn.Conv2d(number_f, number_f, 3, 1, 1, bias=True), 
                nn.ReLU(inplace=True)
                )

layers = [get_conv(number_f) for _ in range(3)]
seq_layers = nn.Sequential(*layers)
print(seq_layers)

