I have a pretrained model with layers stacked in nn.Sequential (I’m using ResNext from link 10)
And I want to replace only the last Linear layer.
I first load the pretrained model and weights as below,
model = resnext_101_64x4d.resnext_101_64x4d
model.load_state_dict(torch.load('resnext_101_64x4d.pth'))

Then how can I replace the last layer?
the model looks like below,
Sequential(
  (0): Conv2d (3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
  (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True)
  (2): ReLU()
   ...
  (10): Sequential(
    (0): Lambda(
    )
    (1): Linear(in_features=2048, out_features=1000)
  )
)

I want to remove the last Linear layer  and then add_module but I don’t know how to remove.
Or is it okay to just replace it by,
model[10].add_module('1', torch.nn.Linear(2048,365))?