Skip to main content
Solved

Pickle File use in CDF function


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 ?

Best answer by vwrocks8

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.

View original

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 

 


  • Practitioner
  • August 18, 2022

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.


kelvin
Seasoned Practitioner
  • Seasoned Practitioner
  • August 18, 2022

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


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings