Two ways for exporting trained models, what are the differences?

What is the differences between

learn.export(‘trained_model.pkl’)

and

callback_fns=[partial(SaveModelCallback, monitor =‘val_loss’, mode =‘auto’, name = 'trained_model )]

in exporting a trained model? is any of them have advantages over the other?

learn.export is used to export your learner and all its related parts (transforms, metrics,…). It’s usually what you want when you’re putting your model out for production. The callback SaveModelCallback periodically saves your learner object while training. By default it saves the model with the best val_loss and saves it as bestmodel. It simply uses the regular learn.save to save your model weights. You could then export this model for inference using:

learn.load('bestmodel')
learn.export('bestmodel.pkl')
3 Likes