algeriapy:

but in the decision layer it has two braches where resnet FC layer is shared:


Your current architecture creates two new classifiers and assigns one to self.classifier and the other one to a new attribute called self.res_model.classifier. Note that you are not replacing the last linear layer of the resnet in the latter case, as it’s assigned to self.res_model.fc (and already replaced with the nn.Sequential module). This isn’t necessarily wrong, but you should be aware that the forward pass of self.res_model will not call self.res_model.classifier.



 algeriapy:

self.weight = Parameter(torch.Tensor(out_features, in_features))


This will use uninitialized memory, which is most likely not what you want.
Don’t use the torch.Tensor constructor, but the factory methods instead (torch.randn, torch.ones, etc.).



 algeriapy:

Is there will be two gradient (from self.classifier and self.res_model.classifier ), In back propagation they summed !!!


No, since you are calculating the loss from one output only (preds in the posted code snippet, which is undefined, so I don’t know which output you are using). If you are calculating the loss from both outputs, both computation paths will be used to calculate the gradients of the parameters in the main branch.



 algeriapy:

What happens to the weights in (self.weight) from Net1, Are they will be learned with the network training or stay fixed as they initialized !!


If you are using the model’s output to calculate the loss (again unclear based on your posted code), then it will be updated unless you freeze the parameters by setting their .requires_grad attribute to False.