Recently I was training a dataset for Facial Age Determination. A considerable amount was spent each time I launched my script.
The Reason: It was retraining the whole dataset at each launch.
Solution : Saving the dataset into a file loading it back.
Serialization allows you to save objects to a file and reload them. I have worked with Java and Python Serialization, and with python its a piece of cake.
There are two options
I would be thus demonstration cpickle store and load through this post. The steps for pickle are the same. Just import pickle instead of cpickle and you are good to go.
In case you are thinking about pickles, (I was while writing the this article), please continue; there's not much I could do!
I am sure the image on the right will help.
The Reason: It was retraining the whole dataset at each launch.
Solution : Saving the dataset into a file loading it back.
Serialization in Python
Serialization allows you to save objects to a file and reload them. I have worked with Java and Python Serialization, and with python its a piece of cake.
There are two options
- Pickle
- CPickle
I would be thus demonstration cpickle store and load through this post. The steps for pickle are the same. Just import pickle instead of cpickle and you are good to go.
Code
This code is tested on Python2 despite the bracketed print statements. These days I am working with Python3, and I am lazy (well not really but I am not making your life more simpler. Yikes already did !)
import cPickle as pickle print ('Script to test the pickle utility') tosave="somedata" filename="persistance.dump" with open(filename,'wb')as fp: pickle.dump(tosave,fp) with open(filename,'rb') as fp: savedval=pickle.load(fp)
In case you are thinking about pickles, (I was while writing the this article), please continue; there's not much I could do!
I am sure the image on the right will help.
No comments:
Post a Comment