Concatenate FC layers to layers of trained model

Hi,

I have a trained model and I wish to try and use it’s inner layers as input for a new model (say, a 2 layer FC model) with a slightly different learning objective. how can I do that?

Hi @gil_bc
If you had defined a particular layer such as self.fc1 = nn.Linear(..) in your original model_1 then you’ll be able to extract the model’s weights using weights = model_1.fc1.weight.data.
You define in model_2 this same layer and initialise it wights and freeze it.

In model_2 code:

self.fc1.weight = weights     #with or without grad

Let me know if this worked.

Some useful discussions that you should look at.

It helped,
and the discussions as well. thanks!

1 Like

Hi @SANTOSH_S

I’m afraid I was still unable to execute what I was trying to do.
I wish to connect a part of my trained network with another untrained network, to learn a new objective.
So let’s say I want to use the first few layers of the trained network, than concatenate to them the new layers and train the whole thing together.

How would you perform such thing?