Saving and reloading a Tabular model in fastai V1


(blissweb) #1

I have trained a tabular model and am attempting to save and reload it.

learn.save('fastai_v1_tabular_test')

now according to the docs you have to run

learn2.load('fastai_v1_tabular_test')

to get it back, but that is dependent upon having already created a
new, blank learn2 object.

The only way I’ve been able to make this work is to create a learn2 object with exactly the same layers configuration as the original.

Is there any way to create a new blank model ?, and then have the layer configurations picked up from the model you are loading ? I think some of the non-tabular models seem to have a pretrained option, but I can’t find this in the tabular docs.


(Dominik Engel) #2

See https://docs.fast.ai/basic_train.html#Saving-and-loading-models

Simply call Learner.save and Learner.load to save and load models. Only the parameters are saved, not the actual architecture (so you’ll need to create your model in the same way before loading weights back in). Models are saved to the path / model_dir directory.

You create the learner as before. If you load you get the trained weights that you have saved. If you do not load any weights, your model is randomly initialized.