Thanks for your reply
Based on what you have pointed out, is that the right way to re-write the previous code?
class alex (nn.Module):
def __init__(self):
        super(alex,self).__init__()
        self.net= models.alexnet(pretrained= True)
        self.feat_model = []
        self.sub_cl1 = []
        self.sub_cl2 = []
        for param in self.net.parameters():
            param.requires_grad=False
        self.feat_model.append(self.net.features)
        self.sub_cl1.append(self.net.classifier[:-2])
        self.sub_cl2.append(self.net.classifier[5:7])
        self.sub_cl2[0][0]=nn.ReLU()

def forward(self,x):
    
          for layer in self.feat_model:
            feature = layer(x)
          x_feat=self.net.avgpool(feature)
          x_feat=x_feat.view(-1,x_feat.size(1)*x_feat.size(2)*x_feat.size(3))                
          for subm1 in self.sub_cl1:
            x_sub_classifier1 = subm1(x_feat)                
          for subm2 in self.sub_cl2:
            model= subm2(x_sub_classifier1)        
          return feature,  x_sub_classifier1,model