Patrice:

I think that this line means all but the last 4 layers of the pretrained model. Please, correct me if I am wrong.


Yes, that;s correct. While this might work for resnet50, it might not for other architectures.



 Patrice:

I guess, I can only index the fully connected layers of a selected network architecture. So, the indexing must be related to the number of fully connected layers in the network structure given that building FCN of an CNN simply consists of replacing the FC layers with convolutional layers. Sorry if it might be a little weird. But ,I am just trying to get it rig


That might be the simplest method. Classification models usually have a classification layer created as model.fc or model.classifier, which you could replace with your custom convs.