Exporting a Model from Google Colab



I’m trying to deploy a model that was trained on a google colab gpu so that I can use it for making predictions on a cpu. I’m trying to do that using the export() and load_learner() functions.

When I try to do load_learner() in google colab everything works fine. However if I download the exported file and try to load it for example using my laptop I get the following error:

RuntimeError: Invalid magic number; corrupt file?

The downloaded file is identical with the file on google colab (md5sum is the same). Fastai was installed using pip install git+https://github.com/fastai/fastai.git on both colab and my local laptop. Both use Python 3.6.
I’ve tried to localize the issue by testing whether I might have a wrong protocol versions of pickle etc. but couldn’t find anything useful.

Any idea on what might be cause of this issue would be highly appreciated.


I think you may not have had the two exact same commits as there was a change from pickle to torch for serialization. Try with v1.0.41 (the last one) on both sides, it should work.


Thanks @sgugger now it works!

(Gavin Armstrong) #4

How did you download the model? After I export the model on colab I can’t seem to find it in the working directory. Thanks

Edit. adding a path to the create_cnn function creates a folder that you can access in colab. Once you see the folder you can double click the pickle file to download the exported model.

learn = create_cnn(data, models.resnet34, metrics=error_rate, path=“content/”)