Lee Lee - 3 years ago 218
Java Question

Issue running tensorflow with java

I am having some issues running tensorflow with java. I am using CUDA 8 with CuDNN 6.

I tried following the quickstart instructions located here: https://www.tensorflow.org/install/install_java and get the following error message when I attempt to run the example java program:

java -cp libtensorflow-1.4.0.jar:. -Djava.library.path=./jni HelloTF

Exception in thread "main" java.lang.UnsatisfiedLinkError: 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.
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:75)
at org.tensorflow.TensorFlow.init(TensorFlow.java:66)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:70)
at org.tensorflow.Graph.<clinit>(Graph.java:258)
at HelloTF.main(HelloTF.java:8)

The jni directory contains the following:

  • libtensorflow_framework.so

  • libtensorflow_jni.so


I then tried installing the binaries from source as suggested here:

This is the output from setting:

org.tensorflow.NativeLibrary: tryLoadLibraryFailed: /path/to/jni/libtensorflow_jni.so: libcublas.so.8.0: cannot open shared object file: No such file or directory
org.tensorflow.NativeLibrary: jniResourceName: org/tensorflow/native/linux-x86_64/libtensorflow_jni.so
org.tensorflow.NativeLibrary: frameworkResourceName: org/tensorflow/native/linux-x86_64/libtensorflow_framework.so

But I still get the same error message when I try and run the example Java program.

What am I doing wrong??

Any help would be greatly appreciated!

Answer Source

The error

Cannot find TensorFlow native library for OS: linux, architecture: x86_64.

is clearly stating that the library is not visible to your software.

To make it available to the Java class, try doing like that (in the same shell obviously):

export LD_LIBRARY_PATH=/the/absolute/path/to/your/library
java -cp libtensorflow-1.4.0.jar:. -Djava.library.path=./jni HelloTF

also ensure you're running the java command from the same directory which contains the /jni directory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download