I have a Java demo working that uses Tensorflow for image classification. It runs okay on Windows, but now I want to run it as a web service from the Java Tomcat web server.
I have added all the Tensorflow jars to Tomcat's lib, but Tensorflow has a jni dependency. I'm not sure how to install and link this so Tensorflow can run on the CentOS Linux server.
I have read this, but I do not need to run python on the server, just access Tensorflow from Java.
Update: **Okay, to get this to work on Tomcat on Windows I do the following,
download libtensorflow.jar from, https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-1.6.0.jar
and then the dll from, https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-windows-x86_64-1.6.0.zip (extract zip to get dll)
See, https://www.tensorflow.org/install/install_java
put the jar in my tomcat lib, and create a tomcat dll dir and put the dll in it
edit my setenv.bat and add the line,
SET CATALINA_OPTS=-Xmx4g -XX:PermSize=128m -XX:MaxPermSize=512m -Djava.library.path=D:\Engineering\apache-tomcat-7.0.50\dll
This works on Windows.
For Linux, CentOS 6, I do the same, but instead of the dll download the so files from, https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-cpu-linux-x86_64-1.6.0.tar.gz
and edit my setenv.sh and add the lines,
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/tomcat8/so"
export JAVA_OPTS="-server -Xmx38g -Djava.library.path=/usr/local/tomcat8/so"
export CATALINA_OPTS="-Djava.library.path=/usr/local/tomcat8/so"
But none of these seem to work, I always get the error,
Cannot find TensorFlow native library for OS: linux, architecture: x86_64. See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/java/README.md for possible solutions (such as building the library from source). Additional information on attempts to find the native library can be obtained by adding org.tensorflow.NativeLibrary.DEBUG=1 to the system properties of the JVM.
I found there is another deployment option by instead just adding the jar,
to lib, and it will magically find the correct so files.
https://mvnrepository.com/artifact/org.tensorflow/libtensorflow_jni
When I try this option it seems to find the so files, but I get this error,
/usr/local/tomcat8/temp/tensorflow_native_libraries-1522357321965-0/libtensorflow_jni.so: /lib64/libc.so.6: version `GLIBC_2.16' not found (required by /usr/local/tomcat8/temp/tensorflow_native_libraries-1522357321965-0/libtensorflow_jni.so)
Seems like Tensorflow only supports a very specific OS and version??
I found this, Error while importing Tensorflow in python2.7 in Ubuntu 12.04. 'GLIBC_2.17 not found'
But have not tried any of the options yet. Does not look promising for a production system.
Looking at what GLIBC is, it is for GPU, but I don't have or need to use a GPU, just want to use the CPU, why is this library required??
** Update So... I tried to build glibc 1.6.0 on Centos6 so that I could use it by following,
https://unix.stackexchange.com/questions/176489/how-to-update-glibc-to-2-14-in-centos-6-5
The steps worked, but it lead to this error trying to run Tensorflow, seems like it has a dependecy on another lib...
error while loading shared libraries: __vdso_time: invalid mode for dlopen()
At this point I'm ready to give up, and try installing Centos7, but this route will require we upgrade 12 production servers...