How to edit forward function of pretrained model from pretrainedmodels library

Hi guys,
I am trying to edit forward function of some pretrained model (f.e. resnet50 or senet154) from pretrainedmodels library by adding additional input parameter.
What do u think about solution like this:

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__() = pretrainedmodels.__dict__["model_name"](pretrained=True)
        self.fc1 = nn.Linear(x_dim+y_dim, output_size_like_in_last_linear)
    def forward(self, x, y):
        x1 =
        x2 = y.
        x =, x2), dim=1)
        x = F.relu(self.fc1(x))
        return x

Do you think it will work proper? Do you have any suggestions?
What I want to do is to consider parameter y in the last layer of the pretrained model.

Yes, this makes sense to me, if you want to consider both the output of the pretrained model and y in a dense layer at the end of your model.

You might want to use net.eval() and net.train() on the pretrained model and set requires_grad depending on whether you want to train the pretrained model or keep the weights fixed while training your own model.

1 Like