Hello!
I’m currently wondering if I can add a layer before and after the transfer learning model.
In many cases
In many cases, for example,
TRANSFER LEARNING FOR COMPUTER VISION TUTORIAL 1,
only one layer is replaced with a new layer.

  
      pytorch.org
  
  
    

Transfer Learning for Computer Vision Tutorial — PyTorch Tutorials 1.6.0... 1



  
  
    
    
  
  


model_ft = models.resnet18(pretrained=True)
num_ftrs = model_ft.fc.in_features
# Here the size of each output sample is set to 2.
# Alternatively, it can be generalized to nn.Linear(num_ftrs, len(class_names)).
model_ft.fc = nn.Linear(num_ftrs, 2)

What want to do
無題のプレゼンテーション960×540 7.89 KB
I would like to add layers to the transferred model, for example, VGG 16.
I can add layers to the transferred model. (I’m not sure this is working😢.)
net2 = models.vgg16(pretrained=use_pretrained)

net2.classifier[6] = nn.Linear(in_features=4096, out_features=2)

# add layers after
net2.classifier.add_module('addition', nn.Linear(2, 2))

However, I cannot know how to insert layers before the transferred model.
And, I am not sure method of adding layers to the transferred model after, the above code.
How do we insert layers to transferred model?
Thank you very much!