Required libraries to run tensorflow on Windows

Hello everyone!

When run libtensorflow-2.7.0.jar, via cmd on a Windows 7 Pro x64 system, I get this error:

E:\libtensorflow>javac -cp libtensorflow-2.7.0.jar HelloTF.java
E:\libtensorflow>java -cp libtensorflow-2.7.0.jar;. -Dorg.tensorflow.NativeLibrary.DEBUG=1 -Djava.library.path=“E:\libtensorflow” HelloTF

libtensorflow270

When testing the “libtensorflow-1.4.0.jar” library, there are no errors:

E:\libtensorflow>javac -cp libtensorflow-1.4.0.jar HelloTF.java
E:\libtensorflow>java -cp libtensorflow-1.4.0.jar;. -Dorg.tensorflow.NativeLibrary.DEBUG=1 -Djava.library.path=“E:\libtensorflow” HelloTF

libtensorflow140

Specifications:

Windows 7 Professional x64 SP1, and also Windows 10 Professional x64 2004.
Packages installed Microsoft Visual C++ 2015-2022 Redistributable x86 and x64.
Tested with jdk-8u371-windows-x64.exe, or jdk-11.0.9_windows-x64_bin.exe, but the result did not change at the output.

HelloTF.java:

import org.tensorflow.Graph;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
import org.tensorflow.TensorFlow;

public class HelloTF {
public static void main(String[] args) throws Exception {
try (Graph g = new Graph()) {
final String value = "Hello from " + TensorFlow.version();

  // Construct the computation graph with a single operation, a constant
  // named "MyConst" with a value "value".
  try (Tensor t = Tensor.create(value.getBytes("UTF-8"))) {
    // The Java API doesn't yet include convenience functions for adding operations.
    g.opBuilder("Const", "MyConst").setAttr("dtype", t.dataType()).setAttr("value", t).build();
  }

  // Execute the "MyConst" operation in a Session.
  try (Session s = new Session(g);
       Tensor output = s.runner().fetch("MyConst").run().get(0)) {
    System.out.println(new String(output.bytesValue(), "UTF-8"));
  }
}

}
}

File links:
libtensorflow-2.7.0.jar
libtensorflow_jni-cpu-windows-x86_64-2.7.0.zip
HelloTF.java

Maybe the system needs to install more additional libraries ?
Please, if you ran this library on Windows 7 x64, or Windows 10 x64, write how to do it correctly.

Those binaries have never been supported for TF 2, development was moved out to SIG-JVM and you should use the binaries from this repo - GitHub - tensorflow/java: Java bindings for TensorFlow, the latest release is 0.5.0 based on TF 2.10.1.

Thanks for your reply,

I made an attempt to run a test program, as in the description on github Example Program .

Used for this:
“maven-3.9.3”
“jdk-11.0.9”
“Microsoft Visual C++ 2015-2022”
“mingv64 x86_64-8.1.0-release-win32-sjlj-rt_v6”

Entered the code through the command line in Windows 7 pro x64, and the program builds ok:

mvn -q -e -X -Djavacpp.platform=windows-x86_64 compile

[INFO] Compiling 1 source file with javac [debug target 11] to target\classes
[DEBUG] incrementalBuildHelper#afterRebuildExecution
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

But on startup there is an error:

mvn -Djavacpp.platform=windows-x86_64 exec:java

Caused by: java.lang.UnsatisfiedLinkError: C:\Users\Николай.javacpp\cache\tensorflow-core-api-0.4.1-windows-x86_64.jar\org\tensorflow\internal\c_api\windows-x86_64\jnitensorflow.dll: Can’t find dependent libraries

Included dependencies in pom.xml:

tensorflow-core-platform 0.4.1
tensorflow-framework 0.4.1
javacpp 1.5.6
protobuf-java 3.19.4

tensorflowtest.zip

Maybe there are not enough dependencies in the pom file, or am I building the project incorrectly?

Is there a reason you need to use version 0.4.1?

It is important for me now to run any java Tensorflow library with a version higher than 2.x.x on a Windows system, but I can’t get the dependencies right.

The error says it can’t load something transitively pulled in from the jnitensorflow dll. I suspect it’s because we build it on Windows 10 (or a Windows Server variant derived from Windows 10) and you’re using Windows 7. You can use a tool like dumpbin which comes with Visual Studio to find the dependencies that dll needs, but I think you might need to build it from source on that platform to make it work.

I will use the same test on Windows 10.
Please, write what libraries you have installed on Windows to use java Tensorflow. Maybe I missed something when reading the documentation.

I very rarely run TF-Java locally on Windows, but I do use it in GitHub Actions runs on their Windows runners, so you could look at the packages installed there. I don’t think we install anything special.