I would like to train my machine learning using Python and libraries such as tensor flow, keras, and scikit-learn. After trained, I would like to export this trained model to a file, so far I have been using the library pickle. I feel that this is pretty standard in any ML project.

However, and the point of this question, is it possible to use this trained model (e.g. a .pkl or .sav file) in C language? When I say "use", I mean passing values to the model and getting a prediction back.

This is somewhat similar to TensorFlow Lite for Microcontrollers, however, I am not sure if this is the most appropriate and easier approach to this problem.


Library http://www.picklingtools.com/

#include "chooseser.h"

// assume that pickle file is "loaded_pkl";
int main()

  Val loaded_pkl;
  LoadValFromFile(loaded_pkl, "my_pkl.pkl", SERIALIZE_P0);
  cout << loaded_pkl << endl;



Pickling is only one of many possible answers. But it's also the one with the most long-term problems since maintenance can become a nightmare.

So, I think the more elegant solution is to put your model behind an API layer and just expose a REST-ful endpoint that can be consumed in any number of languages. That provides you the cleanest approach for the long term while giving you the flexibility to use your model in just about any language.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.