You can just get a list with the required model and add a custom head. Say you want to remove the last layer and replace it with new custom head
learn.model = nn.Sequential(*list(children(learn.model))[:-1], custom_head)
.
Have a look at this: https://github.com/TheShadow29/FAI-notes/blob/master/notebooks/Using-Pretrained-Pytorch-Models.ipynb as well.
4 Likes