Delete a Layer in a Pretrained Model in PyTorch
www.legendu.net › misc › blogApr 16, 2020 · Delete a Layer in a Pretrained Model in PyTorch Apr 16, 2020 It is common to customize a pretrained model by delete the output layer or replace it to the output layer that suits your use case. There are several ways to achieve this in PyTorch. Replace the Fully Connected Layer with an Identity Layer ¶ Define an identity layer.
How to remove the last FC layer from a ResNet model in PyTorch?
stackoverflow.com › questions › 52548174Sep 28, 2018 · If you are looking not just to strip the model of the last FC layer, but to replace it with your own, hence taking advantage of transfer learning technique, you can do so in this way: import torch.nn as nn from collections import OrderedDict n_inputs = model.fc.in_features # add more layers as required classifier = nn.Sequential(OrderedDict([ ('fc1', nn.Linear(n_inputs, 512)) ])) model.fc = classifier