0

I'm trying to install TensorFlow for Java on Windows 10 using this Article . I followed the steps carefully but the windows commands didn't work with me so I decided to do it manually.

The first command is to make the .jar part of the classpath and I did it manually

but the second step was to ensure that the following two files are available to the JVM: the .jar file and the extracted JNI library

but I don't know how to do that manually

The code:

package securityapplication;

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



public class SecurityApplication {

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"));
      }
    }
  }

}

could someone help? cuz my program that uses TensorFlow still have the following error enter image description here

The text in the image is :

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: windows, architecture: x86. 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:66)
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.TensorFlow.init(TensorFlow.java:36)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:40)
at org.tensorflow.Graph.<clinit>(Graph.java:194)
at securityapplication.SecurityApplication.main(SecurityApplication.java:15) Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)

The result after running the first command in cmd:

enter image description here

The result after running the second command in Windows PowerShell:

enter image description here

Any suggestions?!

Thank you

F 505
  • 404
  • 3
  • 10
  • 18
  • That build output is so tiny it’s nearly unreadable. Please include text output as text (preferably in an indented preformatted block), not as an image. – VGR Sep 26 '17 at 19:28
  • is this the result of : javac -cp libtensorflow-1.3.0.jar HelloTF.java ? – Tom Sep 26 '17 at 19:39
  • @VGR I did that. Thank you – F 505 Sep 26 '17 at 19:48
  • @Tom No brother. The commands didn't worked with me I did this step manually where I paste the libtensorflow-1.3.0.jar file in the same directory of HelloTF.java and rerun the code then this result appeared. I don't know how to do the next step manually without using the commands in the article – F 505 Sep 26 '17 at 19:52
  • if you are not using an IDE like eclipse that'll do the building for you, I guess you'll have to compile the java file, in order and prior to run it. When you say the command didn't work with you, what were the outputs ? – Tom Sep 26 '17 at 19:56
  • @Tom Yes I'm using NetBeans IDE 7.4. I'm not sure if I did that correctly. I run those commands on windows PowerShell. The result of the second command will be included in the question – F 505 Sep 26 '17 at 20:18
  • can you try follow the TF guide by using the cmd prompt and not the windows PS ? You can use PS but if you do make sure to follow this guide : https://stackoverflow.com/questions/24464295/compiling-and-running-java-application-using-powershell – Tom Sep 26 '17 at 20:36
  • @Tom I used cmd for the first command as suggested and the result included above – F 505 Sep 26 '17 at 20:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/155362/discussion-between-tom-and-f-505). – Tom Sep 26 '17 at 20:58
  • You have a space after `-D`. It must be a single command line option, i.e. without any space characters in-between: `-Djava.library.path=the_actual_directory` – Holger Sep 27 '17 at 10:00

1 Answers1

0

The first command failure (javac) suggests that the javac command is not in your PATH environment variables. See for example, this StackOverflow question

For the second command failure, I believe the space after -D is what is causing you trouble as Holger suggested.

IDEs like Eclipse and others also provide a means to set the java.library.path property for the JVM (see this StackOverflow answer for example).

Background: TensorFlow for Java consists of a Java library (packaged in a .jar file) and a native library (.dll on Windows, distributed in a .zip file). You need to ensure that the .jar file is in the classpath and the directory containing the .dll is in included in the java.library.path of the JVM when executing a program.

Hope that helps.

ash
  • 6,681
  • 3
  • 18
  • 30