Finetuning a saved model


I trained a model and exported it using learn.export(modelFilename)
I want to load the model and finetuning it again with a different learning rate.
I tried to do learn.load(modelFilename)
but it didn’t work.

What am i missing out?

Hi Yana. What error did you get when you tried to load the learner?

I got an error, it was looking for “.pth” file. learn.export() was saved as “.pkl” file.
I also tried to do learn.export() to be saved as “.pth” file and load it using learn.load()
I still get an error “Learner object is not iterable”

I think i managed to overcome it.
I used and it saved as “.pth” file, when i used that pth file in learn.load() it worked just fine

1 Like

if you want to load the pkl file, you can use:

from fastai.learner import load_learner

learn = load_learner("path/to/your_file.pkl")

This way you do not have to create the learner yourself before loading the model.

Both scenarios have the use case. :slight_smile:


As @zerotosingularity also stated, load_learner is used when model.export() is used.
But load_learner and .export() are used if you want to do inference. When you want to continue fine tuning the model, you need to use .save() and .load(). .save() saves the weights and optionally the optimiser state in .pth file and then you need to create a new Learner class to use .load().

You can find more about this in the docs:

Hope this helps :slight_smile: