Loading pretrained weights for updating some layers in the model

Hi,

I have trained a model, and at the moment I would like to use that model as a layer in my new model.

How it would be possible to initialize my layer with the pretrained model I did before?

Thanks,

class newmodel(nn.Module):
    __init__():
    super(...)
    self.model_as_layer = model_constructor(*args,**kwargs)
    self.model_as_layer.load_state_dict(pretrained_weights)

Just loads weighs while you instantiate your layer

1 Like