Saving a Cats v Dogs Model
This is a minimal example showing how to train a fastai model on Kaggle, and save it so you can use it in your app.
First, import all the stuff we need from fastai:
Download and decompress our dataset, which is pictures of dogs and cats:
We need a way to label our images as dogs or cats. In this dataset, pictures of cats are given a filename that starts with a capital letter:
Now we can create our DataLoaders:
... and train our model, a resnet18 (to keep it small and fast):
Now we can export our trained Learner. This contains all the information needed to run the model:
Finally, open the Kaggle sidebar on the right if it's not already, and find the section marked "Output". Open the /kaggle/working folder, and you'll see model.pkl. Click on it, then click on the menu on the right that appears, and choose "Download". After a few seconds, your model will be downloaded to your computer, where you can then create your app that uses the model.