Is it possible to deploy a python trained machine learning model (e.g. a .pkl file) in C language?

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.

Topic c python

Category Data Science


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.


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;

}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.