Exporting a Model from Google Colab

Hi,

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.
Thanks!

1 Like

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!

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/”)

2 Likes

Any help would be great. Please i am not technical so if you could talk in laymans terms with me, I would appreciate that. I am trying to upload my colab notebook including the Model.PK file but it fails to upload. Has anyone else run into this problem? Also has anyone got a video on how to deploy my model to any free site? A step by step video would be great if anyone has come across that and may have the link.

Thanks in indvance

1 Like

Hi TechJonesAi hope your having fun!

I am trying to upload my colab notebook including the Model.PK file but it fails to upload.

Can you give step by step guide how you are trying to upload your Colab notebook, e.g. from my laptop to Colab. and the error.

Has anyone else run into this problem?

Information above required to answer this question.

Also has anyone got a video on how to deploy my model to any free site? A step by step video would be great if anyone has come across that and may have the link.

I am not aware of any videos’s showing how to deploy your model.You could use this repo https://course-v3.fast.ai/deployment_render.html
as a start. If you get it working on your desktop first, deploying it on any platform, will be much easier.

One of the simplest solutions is https://render.com/ this starts at $5.00 a month I believe.
There is also https://www.heroku.com/ and pythonanywhere.com which have a free starter option.

Cheers mrfabulous1 :smiley::smiley:

Hi MrFabulous1 thanks for the response. To answer your first quesiton, I am trying to upload the files in google colab to github but it keeps saying it fails, i believe it has something to do with the size of my files someone else mentioned before?

Render is only free for the first few months :slight_smile:

oh ok, thanks i guess Heroku it is then.

Hi TechJonesAi
Can you provide a screenshot of what you are doing and the specific error message you are receiving when you attempt to upload ?

Thanks
mrfabulous1 :smiley::smiley: