Loading a Tensorflow.js model from C++/WASM
This is a spike to figure out any method to load a Tensorflow.js model from C++, compiled to WASM with Emscripten em++.
emscripten::val object in C++ at the first line of code. It gives me the
willies to pollute the global namespace, so I create just one global object
and then add properties to it for all other global objects created.
The three EM_JS functions
a somewhat arbitrary divsion of the execution. I wanted confirmation that
the global object persists across these calls (despite the fact that of course
global objects persist).
loadModel just to isolate the async load step
into one function.
The model referenced here
"tf-wasm/e1431.tfjs.model" is not included in this
gist, but any Tensorflow.js GraphModel should work. A LayersModel should also
work by just changing the
tf.loadGraphModel() call to
Loading NPM modules
I was initially confused as to what would be required to make the
'@tensorflow/tfjs-node' or any other NPM module available to the C++ code. But of course, it's all relatively automatic. All that is necessary is to locate a
I have an abstract class
Predictor with with a pure virtual function
with an implemention
Predictor_cc that uses
Tensorflow_cc for its implementation.
I want to implement a
Predictor_js class uses
Tensorflow.js for the implementation.