Why do torchvision models have different prediction layer's name?

I wanted to make a function that take any torchvision model as argument and output the same model with a different output size, but I realized that a simple but annoying problem prevented me from directly doing so : The prediction layers of those models have different names. For example, the last layer of Resnet and Inception is called “fc”, while the last layer of AlexNet and VGG is called “classifier”.

I bypassed this problem by using hasattr(model, "fc"), but it seems a bit odd to me.

Is there a reason for this difference ? Wouldn’t be better to just have one name ?

I guess it would have been better to use a specific naming convention, but since the models were implemented in different releases, by different authors, each with (slightly) different coding styles, the layer names might differ and your check sounds like a good approach to check for the classifiers.

1 Like