Good day folks,
I am trying to do a one time, import of tensorflow and load of a ML model from python in Java. Then pass this model
for predictions. For instance:
-------------
try (Interpreter interp = new SharedInterpreter()){
interp.exec("import tensorflow");
interp.exec("MLmodel= tf.load_model('someModel')");
// Not sure how to create an object of the model, maybe pyObject
} catch (JepException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
----------
// do some operations of data in java then apply the model to the java data
-------------
try (Interpreter interp = new SharedInterpreter()){
// I want to avoid loading the model and importing tensorflow again
interp.exec("x = somemodel(data)");
} catch (JepException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-------
I am aware of pyObjects and pyCallable which seems like the way to go, but as I am a noobie at java, I would need a brief example to see how to implement it.
Points to note:
I tried using:
--------
JepConfig cfg = new JepConfig()
.addSharedModules("numpy,tensorflow");
try {
SharedInterpreter.setConfig(cfg);
} catch (JepException e) {
e.printStackTrace();
}
---------
to set the preloaded modules but sharedInterpreter doesn't have this functionality it seems.
Can anyone help.
Thanks in advance,