How to save (and load) just the body

Once I fine-tune a model, I’d like to perform experiments with different heads but the same well-trained body.

To this end, I’d like to save just the body’s weights, and then instantiate a learner passing those weights like a pretrained model, while passing a head Kaimig-initialized.

How can I do it with fastai?

1 Like

If you use cnn_learner, the body is learn.model[0]. You can then use PyTorch load ans save functions to load/save it.


Great! I just ignored one could separately save chunks of the model (at least, not so easily)

What about for TabularLearner? TabularModel doesn’t seem to support indexing. Is there a way around this?