A question about learn.save

Whether learn.save save the best model that has the lowest error_rate or save the model belongs to the last epoch?
And how can i get the best model score if there is so many epoch that is time assuming to find or when i type “learn.destroy” the message all gone?

1 Like

Hi @zzgong,
The command “learn.save” simply saves the current weights in memory (the active model). Thus, if you run say 10 epochs, it will simply be the latest epoch regardless of how it scored.

If you want to save the best model in the scenario of running say 10 epochs (highly recommended :slight_smile: then you need to use the FastAI SaveModelCallback. I wrote an article here showing how to use it:

Hope that helps!


Thanks for your answer!
And when train done, i export the model to inference. Will learn.export export the best model by default?

Hi @zzgong,
Learn.export will save whatever model is currently loaded.
However, if you use SaveModelCallback during training, then at the end of training it will load the best model automatically…thus you would export the best model if you use learn.export after that.
Thus,as long as you use SaveModelCallback during training, and then run export after training, yes it would export the best model automatically.
Hope that helps!


Thanks for sharing @LessW2020. It is very helpful.

1 Like

@LessW2020 sir how i can save it in .pt format… i need it for android project…so is there anyway to it in .pt format?

Just simply save it as a ‘.pt’. Overall they’re just the same thing with a different format @masudbarki https://discuss.pytorch.org/t/difference-between-saving-a-tensor-via-pt-and-pth/30780

@muellerzr it’s not same sir… i extracted .pt with winrar it extracted… but when i tried to extract the .pth file it didn’t extracted… simple renaming doesn’t do it…

@muellerzr i did try to save it as learn.save(“model.pt”)… but it gave me this file model.pt.pth