calling python machine learning code (keras) in java

465 views
Skip to first unread message

Satyan Singh

unread,
May 6, 2021, 9:27:25 AM5/6/21
to Jep Project
Good day all,
Is there a way to call my python code in java. The python code will be used to load my machine learning model for prediction (keras), as well as train the model. Currently, i am using process builder to run the python scripts. However, the limitation of process builder is: i need to convert the Java float array into a string to feed it to the python script, but the float array is too big to fit into the processBuilder string.

so i have a list of questions for jep users:
1. can i run a python script in java (in the python script i need to import tensorflow, numpy etc)? (if yes: I guess i will have to run the script from my python environment; how will I go about doing this then)

2. how do I feed the float arrays from java directly to the python script then take the outputs of the python script and feed it to java?

Thanks in advance for your help, if possible can you also share some working examples as I am new to java.

best regards,
Satyan



Luís Filipe Nassif

unread,
May 6, 2021, 12:40:04 PM5/6/21
to Satyan Singh, Jep Project

--
You received this message because you are subscribed to the Google Groups "Jep Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jep-project...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jep-project/93da2cef-c34e-4e13-9745-589b7c23ea85n%40googlegroups.com.

Satyan Singh

unread,
May 6, 2021, 1:16:24 PM5/6/21
to Jep Project
Hey Luis, thank you for your reply, 
But maybe I was not clear or I am too much of a noob in programming,

But how do you call the python script in your Java code (*.java) and feed the java arrays to the python script?
Currently, I run the python scripts in JAVA using processBuilder and converting the java array to string then feeding it to python within the processBuilder, but I am limited on the size of the string. 

Luís Filipe Nassif

unread,
May 6, 2021, 5:16:11 PM5/6/21
to Satyan Singh, Jep Project
Sorry, my bad. There is a simple example in the wiki: https://github.com/ninia/jep/wiki/Getting-Started

Also I think you can use JEP NDArrays to pass arrays from java to python, also on the wiki.

Cheers

Satyan Singh

unread,
May 10, 2021, 10:10:38 AM5/10/21
to Jep Project
Thanks Luis for directing me.
Reply all
Reply to author
Forward
0 new messages