Skip to main content

I have one model.pkl file which is a pre-trained Data Science model. I want to load that file inside handler of CDF function and do some prediction. My first question is where to keep that file in CDF. Second is how to load that file inside handler ?

If I put the model.pkl file in “Files” in CDF. Don’t know how to load it and do the prediction, Tried with download_bytes.  Getting error 

 


I would suggest using this method to download the file to the /tmp directory from within the function. Once dowloaded you can treat it as a local file and load it.

pickled_model = pickle.load(open('/tmp/model.pkl', 'rb'))

Assuming this a python pickled model.


As @vwrocks8 suggests, the missing piece seems to be “unpickling” your file, e.g. pickle.load(...). You can do that directly from bytes too.


Reply