I want to use a pretrained DenseNet-121 model which I load directly from Torchvision. However, I want to be able to split the model from one of the transition layers, say, transition2, and use the values up to that point.
Say you have defined a model that follows the same structure as densenet121 till the transition2. Now you want to load the original weights of densenet in your new model. Every layer in your model will have a name and corresponding weights. All the weights of your model are stored as a dictionary, where the key is the layer name and value is the weights of that layer.
To get a part of the model, you can thus only select those (key, value) pairs that you want which in your case are till transition2.
Because of how the pretrained DenseNet model is defined, it has only two children. The entire model up to classifier and the classifier. It seems as though I will have to write the source code myself.