Solved

Pickle File use in CDF function

  • 16 August 2022
  • 3 replies
  • 112 views

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 ?

icon

Best answer by vwrocks8 18 August 2022, 17:53

View original

3 replies

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.

Userlevel 3

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