Thank you Eqy for your reply;
Sorry, I wasn’t clear with my explanations. I’m loading my model with the following code (I have my code of course):
mymodel = MyModelClass()
mymodel.load_state_dict(torch.load(PATH))
mymodel.eval()

My target is to cut any loaded model, without modifying the initial code. Hence being able to loop over all the layers, respecting their order in the neural network loaded, and input at any intermediate layer chosen for the cut.
If you can only show me how to access all the layers of a loaded model, respecting their order in the network, I’ll be able to copy weights and biases and all the parameters of the loaded model, in the new cut model. Actually, all the layers are printed not in order with .keys() and .named_parameters(), and also .state_dict().items(), so I cannot access the layers in their implemented sequence.
Also, I’ve seen that the source code of torchsummary is able to access the layers in their implemented order. They’re using hooks. I’m trying to figure how this works.
Tell me if I’m still not clear. (I’ve been using PyTorch for only 4 months, sorry for my poor level)
Thank you very much
Habib