Assume that we have a model which takes x as input and outputs y at the end, now I want to train it again but give the input to an intermediate layer rather than at the input of the model. May youp please help me how I need to do it with a simple snippet code.
First of all the intermediate level might not have the same input size as the first level, Iād propose to check the input of your layer_of_interest with pre forward hook that outputs the size of input.
Secondly, you can shorten your model using Python slicing and nn.Sequential (this option will work only if your net is already a Sequential, if not find a container in it and slice it)
from = 3 # number of layer_of_interest
new_net = nn.Sequential(*net[from:])