How to save and re-use trained AI models. Python pickling hands-on in a nutshell

Maciej Zalwert
3 min readFeb 9, 2022

After a few hours, you finally trained an AI model in a jupyter notebook in python for one of the Kaggle’s competitions — what now?

Are you going to always go through train and test steps again to show off the results?

For novice AI engineers, researchers without practice and people that started learning python it may be a mystery what to do with trained AI models — how AI model may be saved and used again?

In this article I will show one of the easiest way of saving and reusing AI models.

Let’s get started!

In Python there is a standard library called “pickle” — that pickles objects.

In other programming languages pickling is alternatively known as “serialization”, “marshalling” or “flattening”.

In essence, the main goal of the pickle module is to convert a python object into binary format and save it as a file. Then you can unpickle the file whenever/ wherever you want to and get the object back.

In Python everything is an object, so trained AI models. This means we can easily preserve their state using pickle module.

Let’s see how!

Pickling objects

--

--

Maciej Zalwert

Experienced in building data-intensive solutions for diverse industries