I have to run source code in an environment where I do not have access to third-party libraries and I would like to be able to use a Neural Network model for predictions in that environment. I cannot run compiled code, it has to be source code.
I'd like to train my Neural Network using a popular library like Keras, Pytorch, Tensorflow etc... and convert that model to a source code function that can run in an environment that doesn't have access to that library. So the generated code can't be a wrapper around calls to the library. It needs to have everything it needs inside it to be able to run the Neural Network without external dependencies. And it has to be source code, not compiled code.
While researching this I realised that most libraries will have APIs to save the model to different kinds of serialized format but no way to generate code that could be run on its own.
How would I go about doing that?
Just to be extremely clear here is an example of the kind of code I would like to generate from a neural network model:
function predict(input) {
// Here is all the code that contains the topology and weights of the network
// along with the code needed to load it up into memory and exercise the network,
// using no external libraries.
return output;
}
So what I'm looking for is a library, or a technique that would allow me to do:
var neuralNetworkSourceCode = myNeuralNetworkModel.toSourceCode();
// neuralNetworkSourceCode is a string containing the source code described in the previous example
It could save the source code to a file instead of just producing a string, makes no difference to me. At this point I also don't care about the language it is producing source code in, but ideally it would be in one of these: c, c++, c#, java, python, javascript, go or rust.
Is there a library that does this? If not, how should I go about implementing this functionality.